mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-02-18 16:47:48 +01:00
25 lines
928 B
TypeScript
25 lines
928 B
TypeScript
import { invoke } from '@tauri-apps/api/core';
|
|
import { useMutation } from '@tanstack/react-query';
|
|
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
|
import { useRequestUpdateKey } from './useRequestUpdateKey';
|
|
import { useUpdateAnyHttpRequest } from './useUpdateAnyHttpRequest';
|
|
|
|
export function useCurlToRequest() {
|
|
const workspaceId = useActiveWorkspaceId();
|
|
const updateRequest = useUpdateAnyHttpRequest();
|
|
const { wasUpdatedExternally } = useRequestUpdateKey(null);
|
|
|
|
return useMutation({
|
|
mutationFn: async ({ requestId, command }: { requestId: string; command: string }) => {
|
|
const request: Record<string, unknown> = await invoke('cmd_curl_to_request', {
|
|
command,
|
|
workspaceId,
|
|
});
|
|
delete request.id;
|
|
await updateRequest.mutateAsync({ id: requestId, update: request });
|
|
wasUpdatedExternally(requestId);
|
|
console.log('FOO', request);
|
|
},
|
|
});
|
|
}
|