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

Configure Feed

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

at feat/pgpull 102 lines 2.7 kB view raw
1import { useQuery } from "@tanstack/react-query"; 2import { 3 getAlbum, 4 getAlbums, 5 getArtist, 6 getArtistAlbums, 7 getArtistListeners, 8 getArtists, 9 getArtistTracks, 10 getLovedTracks, 11 getSongByUri, 12 getTracks, 13} from "../api/library"; 14 15export const useSongByUriQuery = (uri: string) => 16 useQuery({ 17 queryKey: ["songByUri", uri], 18 queryFn: () => getSongByUri(uri), 19 enabled: !!uri, 20 }); 21 22export const useArtistTracksQuery = (uri: string, limit = 10) => 23 useQuery({ 24 queryKey: ["artistTracks", uri, limit], 25 queryFn: () => getArtistTracks(uri, limit), 26 enabled: !!uri, 27 }); 28 29export const useArtistAlbumsQuery = (uri: string, limit = 10) => 30 useQuery({ 31 queryKey: ["artistAlbums", uri, limit], 32 queryFn: () => getArtistAlbums(uri, limit), 33 enabled: !!uri, 34 }); 35 36export const useArtistsQuery = (did: string, offset = 0, limit = 30) => 37 useQuery({ 38 queryKey: ["artists", did, offset, limit], 39 queryFn: () => getArtists(did, offset, limit), 40 enabled: !!did, 41 select: (data) => 42 // eslint-disable-next-line @typescript-eslint/no-explicit-any 43 data?.artists.map((x: any) => ({ 44 ...x, 45 scrobbles: x.playCount, 46 })), 47 }); 48 49export const useAlbumsQuery = (did: string, offset = 0, limit = 12) => 50 useQuery({ 51 queryKey: ["albums", did, offset, limit], 52 queryFn: () => getAlbums(did, offset, limit), 53 enabled: !!did, 54 select: (data) => 55 // eslint-disable-next-line @typescript-eslint/no-explicit-any 56 data?.albums.map((x: any) => ({ 57 ...x, 58 scrobbles: x.playCount, 59 })), 60 }); 61 62export const useTracksQuery = (did: string, offset = 0, limit = 20) => 63 useQuery({ 64 queryKey: ["tracks", did, offset, limit], 65 queryFn: () => getTracks(did, offset, limit), 66 enabled: !!did, 67 select: (data) => 68 // eslint-disable-next-line @typescript-eslint/no-explicit-any 69 data?.tracks.map((x: any) => ({ 70 ...x, 71 scrobbles: x.playCount, 72 })), 73 }); 74 75export const useLovedTracksQuery = (did: string, offset = 0, limit = 20) => 76 useQuery({ 77 queryKey: ["lovedTracks", did, offset, limit], 78 queryFn: () => getLovedTracks(did, offset, limit), 79 enabled: !!did, 80 }); 81 82export const useAlbumQuery = (did: string, rkey: string) => 83 useQuery({ 84 queryKey: ["album", did, rkey], 85 queryFn: () => getAlbum(did, rkey), 86 enabled: !!did && !!rkey, 87 }); 88 89export const useArtistQuery = (did: string, rkey: string) => 90 useQuery({ 91 queryKey: ["artist", did, rkey], 92 queryFn: () => getArtist(did, rkey), 93 enabled: !!did && !!rkey, 94 }); 95 96export const useArtistListenersQuery = (uri: string, limit = 10) => 97 useQuery({ 98 queryKey: ["artistListeners", uri, limit], 99 queryFn: () => getArtistListeners(uri, limit), 100 enabled: !!uri, 101 select: (data) => data.listeners, 102 });