mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:14:03 +01:00
Good start to multi-window
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import type { HttpRequest } from '../lib/models';
|
||||
import { getRequest } from '../lib/store';
|
||||
import { requestsQueryKey } from './useRequests';
|
||||
|
||||
export function useUpdateRequest(id: string | null) {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<void, unknown, Partial<HttpRequest>>({
|
||||
mutationFn: async (patch) => {
|
||||
const request = await getRequest(id);
|
||||
@@ -13,9 +15,19 @@ export function useUpdateRequest(id: string | null) {
|
||||
|
||||
const updatedRequest = { ...request, ...patch };
|
||||
|
||||
console.log('UPDATING REQUEST', patch);
|
||||
await invoke('update_request', {
|
||||
request: updatedRequest,
|
||||
});
|
||||
},
|
||||
onMutate: async (patch) => {
|
||||
const request = await getRequest(id);
|
||||
if (request === null) return;
|
||||
queryClient.setQueryData(
|
||||
requestsQueryKey(request?.workspaceId),
|
||||
(requests: HttpRequest[] | undefined) =>
|
||||
requests?.map((r) => (r.id === request.id ? { ...r, ...patch } : r)),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user