Slight refactor to copy-as-curl

This commit is contained in:
Gregory Schier
2024-05-08 00:28:40 -07:00
parent 6639b07568
commit 71b06c5261
3 changed files with 20 additions and 10 deletions

View File

@@ -1,13 +1,17 @@
import { useMutation } from '@tanstack/react-query';
import { invoke } from '@tauri-apps/api/core';
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
import { useState } from 'react';
export function useCopyAsCurl(requestId: string) {
return useMutation<string>({
mutationFn: async () => {
const [checked, setChecked] = useState<boolean>(false);
return [
checked,
async () => {
const cmd: string = await invoke('cmd_request_to_curl', { requestId });
await writeText(cmd);
setChecked(true);
setTimeout(() => setChecked(false), 800);
return cmd;
},
});
] as const;
}