mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
Invalidate playlist list on creation
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
import { useMutation } from '@tanstack/react-query';
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import { HTTPError } from 'ky';
|
import { HTTPError } from 'ky';
|
||||||
import { api } from '/@/renderer/api';
|
import { api } from '/@/renderer/api';
|
||||||
import { CreatePlaylistArgs, CreatePlaylistResponse } from '/@/renderer/api/types';
|
import { CreatePlaylistArgs, CreatePlaylistResponse } from '/@/renderer/api/types';
|
||||||
import { MutationHookArgs } from '/@/renderer/lib/react-query';
|
import { MutationHookArgs } from '/@/renderer/lib/react-query';
|
||||||
import { getServerById } from '/@/renderer/store';
|
import { getServerById } from '/@/renderer/store';
|
||||||
|
import { queryKeys } from '../../../api/query-keys';
|
||||||
|
|
||||||
export const useCreatePlaylist = (args: MutationHookArgs) => {
|
export const useCreatePlaylist = (args: MutationHookArgs) => {
|
||||||
const { options } = args || {};
|
const { options } = args || {};
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation<
|
return useMutation<
|
||||||
CreatePlaylistResponse,
|
CreatePlaylistResponse,
|
||||||
@@ -19,6 +21,12 @@ export const useCreatePlaylist = (args: MutationHookArgs) => {
|
|||||||
if (!server) throw new Error('Server not found');
|
if (!server) throw new Error('Server not found');
|
||||||
return api.controller.createPlaylist({ ...args, apiClientProps: { server } });
|
return api.controller.createPlaylist({ ...args, apiClientProps: { server } });
|
||||||
},
|
},
|
||||||
|
onSuccess: (_args, variables) => {
|
||||||
|
const server = getServerById(variables.serverId);
|
||||||
|
if (server) {
|
||||||
|
queryClient.invalidateQueries(queryKeys.playlists.list(server.id));
|
||||||
|
}
|
||||||
|
},
|
||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user