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

25 lines
935 B
TypeScript
Raw Normal View History

2023-01-12 18:43:25 -08:00
import { useQuery } from '@tanstack/react-query';
import { queryKeys } from '/@/renderer/api/query-keys';
2023-04-27 21:25:57 -07:00
import type { AlbumArtistDetailQuery } from '/@/renderer/api/types';
import { getServerById } from '/@/renderer/store';
2023-01-12 18:43:25 -08:00
import { api } from '/@/renderer/api';
2023-04-27 21:25:57 -07:00
import { QueryHookArgs } from '../../../lib/react-query';
2023-01-12 18:43:25 -08:00
2023-04-27 21:25:57 -07:00
export const useAlbumArtistInfo = (args: QueryHookArgs<AlbumArtistDetailQuery>) => {
2023-07-01 19:10:05 -07:00
const { options, query, serverId } = args || {};
const server = getServerById(serverId);
2023-01-12 18:43:25 -08:00
2023-07-01 19:10:05 -07:00
return useQuery({
enabled: !!server?.id && !!query.id,
queryFn: ({ signal }) => {
if (!server) throw new Error('Server not found');
return api.controller.getAlbumArtistDetail({
apiClientProps: { server, signal },
query,
});
},
queryKey: queryKeys.albumArtists.detail(server?.id || '', query),
...options,
});
2023-01-12 18:43:25 -08:00
};