mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:14:03 +01:00
Create new workspace, and more optimizations
This commit is contained in:
18
src-web/hooks/useCreateWorkspace.ts
Normal file
18
src-web/hooks/useCreateWorkspace.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import type { Workspace } from '../lib/models';
|
||||
|
||||
export function useCreateWorkspace({ navigateAfter }: { navigateAfter: boolean }) {
|
||||
const navigate = useNavigate();
|
||||
return useMutation<string, unknown, Pick<Workspace, 'name'>>({
|
||||
mutationFn: (patch) => {
|
||||
return invoke('create_workspace', patch);
|
||||
},
|
||||
onSuccess: async (workspaceId) => {
|
||||
if (navigateAfter) {
|
||||
navigate(`/workspaces/${workspaceId}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user