mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-19 07:26:59 +01:00
Slight refactor to copy-as-curl
This commit is contained in:
@@ -608,7 +608,7 @@ const SidebarItem = forwardRef(function SidebarItem(
|
||||
const deleteRequest = useDeleteRequest(activeRequest ?? null);
|
||||
const duplicateHttpRequest = useDuplicateHttpRequest({ id: itemId, navigateAfter: true });
|
||||
const duplicateGrpcRequest = useDuplicateGrpcRequest({ id: itemId, navigateAfter: true });
|
||||
const copyAsCurl = useCopyAsCurl(itemId);
|
||||
const [isCopied, copyAsCurl] = useCopyAsCurl(itemId);
|
||||
const sendRequest = useSendRequest(itemId);
|
||||
const sendManyRequests = useSendManyRequests();
|
||||
const latestHttpResponse = useLatestHttpResponse(itemId);
|
||||
@@ -739,10 +739,13 @@ const SidebarItem = forwardRef(function SidebarItem(
|
||||
{
|
||||
key: 'copyCurl',
|
||||
label: 'Copy as Curl',
|
||||
leftSlot: <Icon icon="copy" />,
|
||||
onSelect: async () => {
|
||||
await copyAsCurl.mutateAsync();
|
||||
},
|
||||
leftSlot: (
|
||||
<Icon
|
||||
className={isCopied ? 'text-green-500' : undefined}
|
||||
icon={isCopied ? 'check' : 'copy'}
|
||||
/>
|
||||
),
|
||||
onSelect: copyAsCurl,
|
||||
},
|
||||
{ type: 'separator' },
|
||||
]
|
||||
|
||||
@@ -40,6 +40,7 @@ export type DropdownItemDefault = {
|
||||
key: string;
|
||||
type?: 'default';
|
||||
label: ReactNode;
|
||||
keepOpen?: boolean;
|
||||
hotKeyAction?: HotkeyAction;
|
||||
hotKeyLabelOnly?: boolean;
|
||||
variant?: 'default' | 'danger' | 'notify';
|
||||
@@ -307,7 +308,9 @@ const Menu = forwardRef<Omit<DropdownRef, 'open' | 'isOpen' | 'toggle'>, MenuPro
|
||||
|
||||
const handleSelect = useCallback(
|
||||
(i: DropdownItem) => {
|
||||
handleClose();
|
||||
if (i.type !== 'separator' && !i.keepOpen) {
|
||||
handleClose();
|
||||
}
|
||||
setSelectedIndex(null);
|
||||
if (i.type !== 'separator') {
|
||||
i.onSelect?.();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user