mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-24 02:11:10 +01:00
Typesafe routing and CM line height issue
This commit is contained in:
25
src-web/hooks/useDeleteWorkspace.ts
Normal file
25
src-web/hooks/useDeleteWorkspace.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
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('workspace', { workspaceId: id });
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user