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