A decentralized music tracking and discovery platform built on AT Protocol 馃幍
at fix/spotify 83 lines 1.9 kB view raw
1import { useQuery } from "@tanstack/react-query"; 2import axios from "axios"; 3import { getPlaylists } from "../api/playlists"; 4import { API_URL } from "../consts"; 5 6export const usePlaylistsQuery = (did: string) => 7 useQuery({ 8 queryKey: ["playlists"], 9 queryFn: () => getPlaylists(did), 10 }); 11 12export const usePlaylistQuery = (did: string, rkey: string) => 13 useQuery({ 14 queryKey: ["playlist", did, rkey], 15 queryFn: () => getPlaylists(did), 16 }); 17 18const usePlaylists = () => { 19 const getPlaylists = async ( 20 did: string, 21 ): Promise< 22 { 23 id: string; 24 name: string; 25 picture: string; 26 description?: string; 27 uri?: string; 28 spotifyLink?: string; 29 tidalLink?: string; 30 appleMusicLink?: string; 31 trackCount: number; 32 }[] 33 > => { 34 const response = await axios.get(`${API_URL}/users/${did}/playlists`); 35 return response.data; 36 }; 37 38 const getPlaylist = async ( 39 did: string, 40 rkey: string, 41 ): Promise<{ 42 id: string; 43 name: string; 44 picture: string; 45 description?: string; 46 uri?: string; 47 spotifyLink?: string; 48 tidalLink?: string; 49 appleMusicLink?: string; 50 curatedBy: { 51 id: string; 52 displayName: string; 53 did: string; 54 avatar: string; 55 handle: string; 56 }; 57 trackCount: number; 58 tracks: { 59 id: string; 60 trackNumber: number; 61 album: string; 62 albumArt: string; 63 albumArtist: string; 64 title: string; 65 artist: string; 66 createdAt: string; 67 uri: string; 68 albumUri: string; 69 artistUri: string; 70 duration: number; 71 discNumber: number; 72 }[]; 73 }> => { 74 const response = await axios.get( 75 `${API_URL}/users/${did}/app.rocksky.playlist/${rkey}`, 76 ); 77 return response.data; 78 }; 79 80 return { getPlaylists, getPlaylist }; 81}; 82 83export default usePlaylists;