2023-04-30 18:00:50 -07:00
|
|
|
import { useMutation } from '@tanstack/react-query';
|
2022-12-31 12:40:11 -08:00
|
|
|
import { HTTPError } from 'ky';
|
|
|
|
|
import { api } from '/@/renderer/api';
|
2023-04-27 21:44:25 -07:00
|
|
|
import { CreatePlaylistArgs, CreatePlaylistResponse } from '/@/renderer/api/types';
|
|
|
|
|
import { MutationHookArgs } from '/@/renderer/lib/react-query';
|
|
|
|
|
import { getServerById } from '/@/renderer/store';
|
2022-12-31 12:40:11 -08:00
|
|
|
|
2023-04-27 21:44:25 -07:00
|
|
|
export const useCreatePlaylist = (args: MutationHookArgs) => {
|
|
|
|
|
const { options } = args || {};
|
2022-12-31 12:40:11 -08:00
|
|
|
|
|
|
|
|
return useMutation<
|
2023-04-27 21:44:25 -07:00
|
|
|
CreatePlaylistResponse,
|
2022-12-31 12:40:11 -08:00
|
|
|
HTTPError,
|
2023-04-27 21:44:25 -07:00
|
|
|
Omit<CreatePlaylistArgs, 'server' | 'apiClientProps'>,
|
2022-12-31 12:40:11 -08:00
|
|
|
null
|
|
|
|
|
>({
|
2023-04-27 21:44:25 -07:00
|
|
|
mutationFn: (args) => {
|
|
|
|
|
const server = getServerById(args.serverId);
|
|
|
|
|
if (!server) throw new Error('Server not found');
|
|
|
|
|
return api.controller.createPlaylist({ ...args, apiClientProps: { server } });
|
|
|
|
|
},
|
2022-12-31 12:40:11 -08:00
|
|
|
...options,
|
|
|
|
|
});
|
|
|
|
|
};
|