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

22 lines
821 B
TypeScript
Raw Normal View History

2022-12-30 21:04:06 -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 { AlbumArtistListQuery } from '/@/renderer/api/types';
import { getServerById } from '/@/renderer/store';
2022-12-30 21:04:06 -08:00
import { api } from '/@/renderer/api';
2023-04-27 21:25:57 -07:00
import { QueryHookArgs } from '../../../lib/react-query';
2022-12-30 21:04:06 -08:00
2023-04-27 21:25:57 -07:00
export const useAlbumArtistList = (args: QueryHookArgs<AlbumArtistListQuery>) => {
const { options, query, serverId } = args || {};
const server = getServerById(serverId);
2022-12-30 21:04:06 -08:00
return useQuery({
enabled: !!server?.id,
2023-04-27 21:25:57 -07:00
queryFn: ({ signal }) => {
if (!server) throw new Error('Server not found');
api.controller.getAlbumArtistList({ apiClientProps: { server, signal }, query });
},
2022-12-30 21:04:06 -08:00
queryKey: queryKeys.albumArtists.list(server?.id || '', query),
...options,
});
};