Invalidate playlist list on creation
This commit is contained in:
parent
2101f1e9a7
commit
3dfeed1432
1 changed files with 9 additions and 1 deletions
|
@ -1,12 +1,14 @@
|
|||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { HTTPError } from 'ky';
|
||||
import { api } from '/@/renderer/api';
|
||||
import { CreatePlaylistArgs, CreatePlaylistResponse } from '/@/renderer/api/types';
|
||||
import { MutationHookArgs } from '/@/renderer/lib/react-query';
|
||||
import { getServerById } from '/@/renderer/store';
|
||||
import { queryKeys } from '../../../api/query-keys';
|
||||
|
||||
export const useCreatePlaylist = (args: MutationHookArgs) => {
|
||||
const { options } = args || {};
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<
|
||||
CreatePlaylistResponse,
|
||||
|
@ -19,6 +21,12 @@ export const useCreatePlaylist = (args: MutationHookArgs) => {
|
|||
if (!server) throw new Error('Server not found');
|
||||
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,
|
||||
});
|
||||
};
|
||||
|
|
Reference in a new issue