feishin/src/renderer/features/artists/queries/artist-list-count-query.ts

32 lines
1 KiB
TypeScript
Raw Normal View History

2025-04-23 23:27:06 -07:00
import { useQuery } from '@tanstack/react-query';
2025-04-23 23:27:06 -07:00
import { api } from '/@/renderer/api';
import { queryKeys } from '/@/renderer/api/query-keys';
import { QueryHookArgs } from '/@/renderer/lib/react-query';
import { getServerById } from '/@/renderer/store';
2025-05-20 19:23:36 -07:00
import { ArtistListQuery } from '/@/shared/types/domain-types';
2025-04-23 23:27:06 -07:00
export const useArtistListCount = (args: QueryHookArgs<ArtistListQuery>) => {
const { options, query, serverId } = args;
const server = getServerById(serverId);
return useQuery({
enabled: !!serverId,
queryFn: ({ signal }) => {
if (!server) throw new Error('Server not found');
return api.controller.getArtistListCount({
apiClientProps: {
server,
signal,
},
query,
});
},
queryKey: queryKeys.albumArtists.count(
serverId || '',
Object.keys(query).length === 0 ? undefined : query,
),
...options,
});
};