mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-06 20:10:12 +02:00
123842dfda
- this query in some cases can return a very large amount of data, depending on the size of the user's library - increasing the cacheTime reduces the frequency of fetches while disabling structuralSharing reduces the need for react-query to do a deep equality comparison for the cache
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import { queryOptions } from '@tanstack/react-query';
|
|
|
|
import { api } from '/@/renderer/api';
|
|
import { queryKeys } from '/@/renderer/api/query-keys';
|
|
import { QueryHookArgs } from '/@/renderer/lib/react-query';
|
|
import { MusicFolderListQuery, TagListQuery, UserListQuery } from '/@/shared/types/domain-types';
|
|
|
|
export const sharedQueries = {
|
|
musicFolders: (args: QueryHookArgs<MusicFolderListQuery>) => {
|
|
return queryOptions({
|
|
queryFn: ({ signal }) => {
|
|
return api.controller.getMusicFolderList({
|
|
apiClientProps: { serverId: args.serverId, signal },
|
|
});
|
|
},
|
|
queryKey: queryKeys.musicFolders.list(args.serverId),
|
|
...args.options,
|
|
});
|
|
},
|
|
roles: (args: QueryHookArgs<object>) => {
|
|
return queryOptions({
|
|
queryFn: ({ signal }) => {
|
|
return api.controller.getRoles({
|
|
apiClientProps: { serverId: args.serverId, signal },
|
|
});
|
|
},
|
|
queryKey: queryKeys.roles.list(args.serverId || ''),
|
|
...args.options,
|
|
});
|
|
},
|
|
tagList: (args: QueryHookArgs<TagListQuery>) => {
|
|
return queryOptions({
|
|
gcTime: 1000 * 60 * 24,
|
|
queryFn: ({ signal }) => {
|
|
return api.controller.getTagList({
|
|
apiClientProps: { serverId: args.serverId, signal },
|
|
query: args.query,
|
|
});
|
|
},
|
|
queryKey: queryKeys.tags.list(args.serverId || '', args.query.type),
|
|
staleTime: 1000 * 60 * 24,
|
|
structuralSharing: false,
|
|
...args.options,
|
|
});
|
|
},
|
|
users: (args: QueryHookArgs<UserListQuery>) => {
|
|
return queryOptions({
|
|
queryFn: ({ signal }) => {
|
|
return api.controller.getUserList({
|
|
apiClientProps: { serverId: args.serverId, signal },
|
|
query: args.query,
|
|
});
|
|
},
|
|
queryKey: queryKeys.users.list(args.serverId || '', args.query),
|
|
...args.options,
|
|
});
|
|
},
|
|
};
|