mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 10:03:33 +00:00
upgrade and refactor for react-query v5
This commit is contained in:
parent
dd70d30cd3
commit
8115963264
94 changed files with 1650 additions and 1750 deletions
60
src/renderer/features/songs/api/songs-api.ts
Normal file
60
src/renderer/features/songs/api/songs-api.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { queryOptions } from '@tanstack/react-query';
|
||||
|
||||
import { api } from '/@/renderer/api';
|
||||
import { controller } from '/@/renderer/api/controller';
|
||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||
import { QueryHookArgs } from '/@/renderer/lib/react-query';
|
||||
import { getServerById } from '/@/renderer/store';
|
||||
import { SimilarSongsQuery, SongListQuery } from '/@/shared/types/domain-types';
|
||||
|
||||
export const songsQueries = {
|
||||
list: (args: QueryHookArgs<SongListQuery>, imageSize?: number) => {
|
||||
return queryOptions({
|
||||
queryFn: ({ signal }) => {
|
||||
const server = getServerById(args.serverId);
|
||||
if (!server) throw new Error('Server not found');
|
||||
return controller.getSongList({
|
||||
apiClientProps: { server, signal },
|
||||
query: { ...args.query, imageSize },
|
||||
});
|
||||
},
|
||||
queryKey: queryKeys.songs.list(args.serverId || '', { ...args.query, imageSize }),
|
||||
...args.options,
|
||||
});
|
||||
},
|
||||
listCount: (args: QueryHookArgs<SongListQuery>) => {
|
||||
return queryOptions({
|
||||
queryFn: ({ signal }) => {
|
||||
const server = getServerById(args.serverId);
|
||||
if (!server) throw new Error('Server not found');
|
||||
return api.controller.getSongListCount({
|
||||
apiClientProps: { server, signal },
|
||||
query: args.query,
|
||||
});
|
||||
},
|
||||
queryKey: queryKeys.songs.count(
|
||||
args.serverId || '',
|
||||
Object.keys(args.query).length === 0 ? undefined : args.query,
|
||||
),
|
||||
...args.options,
|
||||
});
|
||||
},
|
||||
similar: (args: QueryHookArgs<SimilarSongsQuery>) => {
|
||||
return queryOptions({
|
||||
queryFn: ({ signal }) => {
|
||||
const server = getServerById(args.serverId);
|
||||
if (!server) throw new Error('Server not found');
|
||||
return api.controller.getSimilarSongs({
|
||||
apiClientProps: { server, signal },
|
||||
query: {
|
||||
albumArtistIds: args.query.albumArtistIds,
|
||||
count: args.query.count ?? 50,
|
||||
songId: args.query.songId,
|
||||
},
|
||||
});
|
||||
},
|
||||
queryKey: queryKeys.songs.similar(args.serverId || '', args.query),
|
||||
...args.options,
|
||||
});
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue