mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:14:03 +01:00
Refactor hooks to be easier to use
This commit is contained in:
23
src-web/hooks/useUpdateRequest.ts
Normal file
23
src-web/hooks/useUpdateRequest.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import type { HttpRequest } from '../lib/models';
|
||||
|
||||
export function useUpdateRequest(request: HttpRequest | null) {
|
||||
return useMutation<void, unknown, Partial<HttpRequest>>({
|
||||
mutationFn: async (patch) => {
|
||||
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', ''),
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user