2022-12-31 03:46:12 -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 { PlaylistListQuery } from '/@/renderer/api/types';
|
2022-12-31 03:46:12 -08:00
|
|
|
import type { QueryOptions } from '/@/renderer/lib/react-query';
|
2023-04-27 21:25:57 -07:00
|
|
|
import { getServerById } from '/@/renderer/store';
|
2022-12-31 03:46:12 -08:00
|
|
|
import { api } from '/@/renderer/api';
|
|
|
|
|
|
2023-04-27 21:25:57 -07:00
|
|
|
export const usePlaylistList = (args: {
|
2023-07-01 19:10:05 -07:00
|
|
|
options?: QueryOptions;
|
|
|
|
|
query: PlaylistListQuery;
|
|
|
|
|
serverId?: string;
|
2023-04-27 21:25:57 -07:00
|
|
|
}) => {
|
2023-07-01 19:10:05 -07:00
|
|
|
const { options, query, serverId } = args;
|
|
|
|
|
const server = getServerById(serverId);
|
2022-12-31 03:46:12 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return useQuery({
|
|
|
|
|
cacheTime: 1000 * 60 * 60,
|
|
|
|
|
enabled: !!server?.id,
|
|
|
|
|
queryFn: ({ signal }) => {
|
|
|
|
|
if (!server) throw new Error('Server not found');
|
|
|
|
|
return api.controller.getPlaylistList({ apiClientProps: { server, signal }, query });
|
|
|
|
|
},
|
|
|
|
|
queryKey: queryKeys.playlists.list(server?.id || '', query),
|
|
|
|
|
...options,
|
|
|
|
|
});
|
2022-12-31 03:46:12 -08:00
|
|
|
};
|