feat(web/m7-352): kind-aware createPlaylistsQuery + system-playlists-status helper
This commit is contained in:
@@ -3,13 +3,16 @@ import { apiFetch } from './client';
|
||||
import { qk } from './queries';
|
||||
import type { Playlist, PlaylistDetail } from './types';
|
||||
|
||||
export type PlaylistKind = 'user' | 'system' | 'all';
|
||||
|
||||
export type ListPlaylistsResponse = {
|
||||
owned: Playlist[];
|
||||
public: Playlist[];
|
||||
};
|
||||
|
||||
export async function listPlaylists(): Promise<ListPlaylistsResponse> {
|
||||
return (await apiFetch('/api/playlists', { method: 'GET' })) as ListPlaylistsResponse;
|
||||
export async function listPlaylists(kind?: PlaylistKind): Promise<ListPlaylistsResponse> {
|
||||
const k = kind ?? 'user';
|
||||
return (await apiFetch(`/api/playlists?kind=${k}`, { method: 'GET' })) as ListPlaylistsResponse;
|
||||
}
|
||||
|
||||
export async function getPlaylist(id: string): Promise<PlaylistDetail> {
|
||||
@@ -73,10 +76,10 @@ export async function reorderPlaylist(playlistID: string, orderedPositions: numb
|
||||
})) as PlaylistDetail;
|
||||
}
|
||||
|
||||
export function createPlaylistsQuery() {
|
||||
export function createPlaylistsQuery(kind?: PlaylistKind) {
|
||||
return createQuery({
|
||||
queryKey: qk.playlists(),
|
||||
queryFn: listPlaylists,
|
||||
queryKey: qk.playlists(kind),
|
||||
queryFn: () => listPlaylists(kind),
|
||||
staleTime: 30_000
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user