mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-16 08:36:40 +01:00
19 lines
623 B
TypeScript
19 lines
623 B
TypeScript
import { useMutation } from '@tanstack/react-query';
|
|
import { invoke } from '@tauri-apps/api';
|
|
import type { HttpRequest } from '../lib/models';
|
|
import { getRequest } from '../lib/store';
|
|
|
|
export function useUpdateAnyRequest() {
|
|
return useMutation<void, unknown, Partial<HttpRequest> & { id: string }>({
|
|
mutationFn: async (patch) => {
|
|
const request = await getRequest(patch.id);
|
|
if (request === null) {
|
|
throw new Error("Can't update a null request");
|
|
}
|
|
|
|
const updatedRequest = { ...request, ...patch };
|
|
await invoke('update_request', { request: updatedRequest });
|
|
},
|
|
});
|
|
}
|