mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-16 14:06:49 +01:00
22 lines
629 B
TypeScript
22 lines
629 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 useUpdateRequest(id: string | null) {
|
|
return useMutation<void, unknown, Partial<HttpRequest>>({
|
|
mutationFn: async (patch) => {
|
|
const request = await getRequest(id);
|
|
if (request == null) {
|
|
throw new Error("Can't update a null request");
|
|
}
|
|
|
|
const updatedRequest = { ...request, ...patch };
|
|
|
|
await invoke('update_request', {
|
|
request: updatedRequest,
|
|
});
|
|
},
|
|
});
|
|
}
|