A decentralized music tracking and discovery platform built on AT Protocol 馃幍 rocksky.app
spotify atproto lastfm musicbrainz scrobbling listenbrainz
97
fork

Configure Feed

Select the types of activity you want to include in your feed.

at feat/pgpull 114 lines 2.4 kB view raw
1import { useMutation } from "@tanstack/react-query"; 2import axios from "axios"; 3import { next, pause, play, previous, seek } from "../api/spotify"; 4import { API_URL } from "../consts"; 5 6export const usePlayMutation = () => 7 useMutation({ 8 mutationFn: play, 9 }); 10 11export const usePauseMutation = () => 12 useMutation({ 13 mutationFn: pause, 14 }); 15 16export const useNextMutation = () => 17 useMutation({ 18 mutationFn: next, 19 }); 20 21export const usePreviousMutation = () => 22 useMutation({ 23 mutationFn: previous, 24 }); 25 26export const useSeekMutation = () => 27 useMutation({ 28 mutationFn: seek, 29 }); 30 31function useSpotify() { 32 const play = async () => { 33 const response = await axios.put( 34 `${API_URL}/spotify/play`, 35 {}, 36 { 37 headers: { 38 "Content-Type": "application/json", 39 Authorization: `Bearer ${localStorage.getItem("token")}`, 40 }, 41 }, 42 ); 43 return response.data; 44 }; 45 46 const pause = async () => { 47 const response = await axios.put( 48 `${API_URL}/spotify/pause`, 49 {}, 50 { 51 headers: { 52 "Content-Type": "application/json", 53 Authorization: `Bearer ${localStorage.getItem("token")}`, 54 }, 55 }, 56 ); 57 return response.data; 58 }; 59 60 const next = async () => { 61 const response = await axios.post( 62 `${API_URL}/spotify/next`, 63 {}, 64 { 65 headers: { 66 "Content-Type": "application/json", 67 Authorization: `Bearer ${localStorage.getItem("token")}`, 68 }, 69 }, 70 ); 71 return response.data; 72 }; 73 74 const previous = async () => { 75 const response = await axios.post( 76 `${API_URL}/spotify/previous`, 77 {}, 78 { 79 headers: { 80 "Content-Type": "application/json", 81 Authorization: `Bearer ${localStorage.getItem("token")}`, 82 }, 83 }, 84 ); 85 return response.data; 86 }; 87 88 const seek = async (position_ms: number) => { 89 const response = await axios.put( 90 `${API_URL}/spotify/seek`, 91 {}, 92 { 93 headers: { 94 "Content-Type": "application/json", 95 Authorization: `Bearer ${localStorage.getItem("token")}`, 96 }, 97 params: { 98 position_ms, 99 }, 100 }, 101 ); 102 return response.data; 103 }; 104 105 return { 106 play, 107 pause, 108 next, 109 previous, 110 seek, 111 }; 112} 113 114export default useSpotify;