mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-16 08:36:40 +01:00
25 lines
826 B
TypeScript
25 lines
826 B
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
import { invoke } from '@tauri-apps/api';
|
|
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
|
import { useRoutes } from './useRoutes';
|
|
import { workspacesQueryKey } from './useWorkspaces';
|
|
|
|
export function useDeleteWorkspace(id: string | null) {
|
|
const queryClient = useQueryClient();
|
|
const activeWorkspaceId = useActiveWorkspaceId();
|
|
const routes = useRoutes();
|
|
return useMutation<void, string>({
|
|
mutationFn: async () => {
|
|
if (id === null) return;
|
|
await invoke('delete_workspace', { id });
|
|
},
|
|
onSuccess: async () => {
|
|
if (id === null) return;
|
|
await queryClient.invalidateQueries(workspacesQueryKey());
|
|
if (id === activeWorkspaceId) {
|
|
routes.navigate('workspaces');
|
|
}
|
|
},
|
|
});
|
|
}
|