mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 13:43:39 +01:00
27 lines
878 B
TypeScript
27 lines
878 B
TypeScript
import { useMutation } from '@tanstack/react-query';
|
|
import { invoke } from '@tauri-apps/api';
|
|
import type { HttpRequest } from '../lib/models';
|
|
import { useRequests } from './useRequests';
|
|
|
|
export function useUpdateAnyRequest() {
|
|
const requests = useRequests();
|
|
return useMutation<void, unknown, Partial<HttpRequest> & { id: string }>({
|
|
mutationFn: async (patch) => {
|
|
const request = requests.find((r) => r.id === patch.id) ?? null;
|
|
if (request === null) {
|
|
throw new Error("Can't update a null request");
|
|
}
|
|
|
|
const updatedRequest = { ...request, ...patch };
|
|
|
|
await invoke('update_request', {
|
|
request: {
|
|
...updatedRequest,
|
|
createdAt: updatedRequest.createdAt.toISOString().replace('Z', ''),
|
|
updatedAt: updatedRequest.updatedAt.toISOString().replace('Z', ''),
|
|
},
|
|
});
|
|
},
|
|
});
|
|
}
|