mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-14 21:23:40 +01:00
20 lines
737 B
TypeScript
20 lines
737 B
TypeScript
import { useMutation } from '@tanstack/react-query';
|
|
import type { Workspace } from '@yaakapp/api';
|
|
import { getWorkspace } from '../lib/store';
|
|
import { invokeCmd } from '../lib/tauri';
|
|
|
|
export function useUpdateWorkspace(id: string | null) {
|
|
return useMutation<void, unknown, Partial<Workspace> | ((w: Workspace) => Workspace)>({
|
|
mutationKey: ['update_workspace', id],
|
|
mutationFn: async (v) => {
|
|
const workspace = await getWorkspace(id);
|
|
if (workspace == null) {
|
|
throw new Error("Can't update a null workspace");
|
|
}
|
|
|
|
const newWorkspace = typeof v === 'function' ? v(workspace) : { ...workspace, ...v };
|
|
await invokeCmd('cmd_update_workspace', { workspace: newWorkspace });
|
|
},
|
|
});
|
|
}
|