feishin/src/renderer/api/query-keys.ts

129 lines
5 KiB
TypeScript
Raw Normal View History

2023-05-20 22:40:22 -07:00
import { QueryFunctionContext } from '@tanstack/react-query';
2022-12-30 21:04:06 -08:00
import type {
AlbumListQuery,
SongListQuery,
AlbumDetailQuery,
AlbumArtistListQuery,
ArtistListQuery,
2022-12-31 03:46:12 -08:00
PlaylistListQuery,
2022-12-31 12:43:32 -08:00
PlaylistDetailQuery,
2022-12-31 18:03:26 -08:00
PlaylistSongListQuery,
UserListQuery,
2023-01-08 20:45:38 -08:00
AlbumArtistDetailQuery,
2023-01-12 18:43:25 -08:00
TopSongListQuery,
2023-05-19 00:14:41 -07:00
SearchQuery,
2023-05-19 22:20:32 -07:00
SongDetailQuery,
2023-05-21 07:30:28 -07:00
RandomSongListQuery,
2023-06-02 23:54:34 -07:00
LyricsQuery,
2023-06-08 03:40:34 -07:00
LyricSearchQuery,
2022-12-30 21:04:06 -08:00
} from './types';
2022-12-19 15:59:14 -08:00
2023-05-20 22:40:22 -07:00
export const queryKeys: Record<
string,
Record<string, (...props: any) => QueryFunctionContext['queryKey']>
> = {
2022-12-30 21:04:06 -08:00
albumArtists: {
2023-01-08 20:45:38 -08:00
detail: (serverId: string, query?: AlbumArtistDetailQuery) => {
2022-12-31 12:43:32 -08:00
if (query) return [serverId, 'albumArtists', 'detail', query] as const;
return [serverId, 'albumArtists', 'detail'] as const;
},
list: (serverId: string, query?: AlbumArtistListQuery) => {
if (query) return [serverId, 'albumArtists', 'list', query] as const;
return [serverId, 'albumArtists', 'list'] as const;
},
2022-12-30 21:04:06 -08:00
root: (serverId: string) => [serverId, 'albumArtists'] as const,
2023-01-12 18:43:25 -08:00
topSongs: (serverId: string, query?: TopSongListQuery) => {
if (query) return [serverId, 'albumArtists', 'topSongs', query] as const;
return [serverId, 'albumArtists', 'topSongs'] as const;
},
2022-12-30 21:04:06 -08:00
},
2022-12-19 15:59:14 -08:00
albums: {
2022-12-30 21:04:06 -08:00
detail: (serverId: string, query?: AlbumDetailQuery) =>
2022-12-19 15:59:14 -08:00
[serverId, 'albums', 'detail', query] as const,
2022-12-31 12:43:32 -08:00
list: (serverId: string, query?: AlbumListQuery) => {
if (query) return [serverId, 'albums', 'list', query] as const;
return [serverId, 'albums', 'list'] as const;
},
2022-12-30 21:04:06 -08:00
root: (serverId: string) => [serverId, 'albums'],
2022-12-19 15:59:14 -08:00
serverRoot: (serverId: string) => [serverId, 'albums'],
songs: (serverId: string, query: SongListQuery) =>
[serverId, 'albums', 'songs', query] as const,
},
2022-12-30 21:04:06 -08:00
artists: {
2022-12-31 12:43:32 -08:00
list: (serverId: string, query?: ArtistListQuery) => {
if (query) return [serverId, 'artists', 'list', query] as const;
return [serverId, 'artists', 'list'] as const;
},
2022-12-30 21:04:06 -08:00
root: (serverId: string) => [serverId, 'artists'] as const,
},
2022-12-19 15:59:14 -08:00
genres: {
list: (serverId: string) => [serverId, 'genres', 'list'] as const,
root: (serverId: string) => [serverId, 'genres'] as const,
},
2022-12-20 19:11:33 -08:00
musicFolders: {
list: (serverId: string) => [serverId, 'musicFolders', 'list'] as const,
},
2022-12-31 03:46:12 -08:00
playlists: {
2022-12-31 12:43:32 -08:00
detail: (serverId: string, id?: string, query?: PlaylistDetailQuery) => {
2022-12-31 18:03:26 -08:00
if (query) return [serverId, 'playlists', id, 'detail', query] as const;
if (id) return [serverId, 'playlists', id, 'detail'] as const;
2022-12-31 12:43:32 -08:00
return [serverId, 'playlists', 'detail'] as const;
},
2023-01-02 02:04:23 -08:00
detailSongList: (serverId: string, id: string, query?: PlaylistSongListQuery) => {
if (query) return [serverId, 'playlists', id, 'detailSongList', query] as const;
if (id) return [serverId, 'playlists', id, 'detailSongList'] as const;
return [serverId, 'playlists', 'detailSongList'] as const;
},
2022-12-31 12:43:32 -08:00
list: (serverId: string, query?: PlaylistListQuery) => {
if (query) return [serverId, 'playlists', 'list', query] as const;
return [serverId, 'playlists', 'list'] as const;
},
2022-12-31 03:46:12 -08:00
root: (serverId: string) => [serverId, 'playlists'] as const,
2023-05-21 07:30:28 -07:00
songList: (serverId: string, id?: string, query?: PlaylistSongListQuery) => {
if (query && id) return [serverId, 'playlists', id, 'songList', query] as const;
2022-12-31 18:03:26 -08:00
if (id) return [serverId, 'playlists', id, 'songList'] as const;
return [serverId, 'playlists', 'songList'] as const;
},
2022-12-31 03:46:12 -08:00
},
2023-05-19 00:14:41 -07:00
search: {
list: (serverId: string, query?: SearchQuery) => {
if (query) return [serverId, 'search', 'list', query] as const;
return [serverId, 'search', 'list'] as const;
},
root: (serverId: string) => [serverId, 'search'] as const,
},
2022-12-19 15:59:14 -08:00
server: {
root: (serverId: string) => [serverId] as const,
},
songs: {
2023-05-19 22:20:32 -07:00
detail: (serverId: string, query?: SongDetailQuery) => {
if (query) return [serverId, 'songs', 'detail', query] as const;
return [serverId, 'songs', 'detail'] as const;
},
2022-12-31 12:43:32 -08:00
list: (serverId: string, query?: SongListQuery) => {
if (query) return [serverId, 'songs', 'list', query] as const;
return [serverId, 'songs', 'list'] as const;
},
2023-06-02 23:54:34 -07:00
lyrics: (serverId: string, query?: LyricsQuery) => {
if (query) return [serverId, 'song', 'lyrics', query] as const;
return [serverId, 'song', 'lyrics'] as const;
},
2023-06-08 03:40:34 -07:00
lyricsSearch: (query?: LyricSearchQuery) => {
if (query) return ['lyrics', 'search', query] as const;
return ['lyrics', 'search'] as const;
},
2023-05-21 07:30:28 -07:00
randomSongList: (serverId: string, query?: RandomSongListQuery) => {
if (query) return [serverId, 'songs', 'randomSongList', query] as const;
return [serverId, 'songs', 'randomSongList'] as const;
},
2022-12-30 21:04:06 -08:00
root: (serverId: string) => [serverId, 'songs'] as const,
2022-12-19 15:59:14 -08:00
},
users: {
list: (serverId: string, query?: UserListQuery) => {
if (query) return [serverId, 'users', 'list', query] as const;
return [serverId, 'users', 'list'] as const;
},
root: (serverId: string) => [serverId, 'users'] as const,
},
2022-12-19 15:59:14 -08:00
};