mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-01 15:03:11 +02: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 deleteRequest = useDeleteRequest(activeRequest ?? null);
|
||||||
const duplicateHttpRequest = useDuplicateHttpRequest({ id: itemId, navigateAfter: true });
|
const duplicateHttpRequest = useDuplicateHttpRequest({ id: itemId, navigateAfter: true });
|
||||||
const duplicateGrpcRequest = useDuplicateGrpcRequest({ 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 sendRequest = useSendRequest(itemId);
|
||||||
const sendManyRequests = useSendManyRequests();
|
const sendManyRequests = useSendManyRequests();
|
||||||
const latestHttpResponse = useLatestHttpResponse(itemId);
|
const latestHttpResponse = useLatestHttpResponse(itemId);
|
||||||
@@ -739,10 +739,13 @@ const SidebarItem = forwardRef(function SidebarItem(
|
|||||||
{
|
{
|
||||||
key: 'copyCurl',
|
key: 'copyCurl',
|
||||||
label: 'Copy as Curl',
|
label: 'Copy as Curl',
|
||||||
leftSlot: <Icon icon="copy" />,
|
leftSlot: (
|
||||||
onSelect: async () => {
|
<Icon
|
||||||
await copyAsCurl.mutateAsync();
|
className={isCopied ? 'text-green-500' : undefined}
|
||||||
},
|
icon={isCopied ? 'check' : 'copy'}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
onSelect: copyAsCurl,
|
||||||
},
|
},
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ export type DropdownItemDefault = {
|
|||||||
key: string;
|
key: string;
|
||||||
type?: 'default';
|
type?: 'default';
|
||||||
label: ReactNode;
|
label: ReactNode;
|
||||||
|
keepOpen?: boolean;
|
||||||
hotKeyAction?: HotkeyAction;
|
hotKeyAction?: HotkeyAction;
|
||||||
hotKeyLabelOnly?: boolean;
|
hotKeyLabelOnly?: boolean;
|
||||||
variant?: 'default' | 'danger' | 'notify';
|
variant?: 'default' | 'danger' | 'notify';
|
||||||
@@ -307,7 +308,9 @@ const Menu = forwardRef<Omit<DropdownRef, 'open' | 'isOpen' | 'toggle'>, MenuPro
|
|||||||
|
|
||||||
const handleSelect = useCallback(
|
const handleSelect = useCallback(
|
||||||
(i: DropdownItem) => {
|
(i: DropdownItem) => {
|
||||||
handleClose();
|
if (i.type !== 'separator' && !i.keepOpen) {
|
||||||
|
handleClose();
|
||||||
|
}
|
||||||
setSelectedIndex(null);
|
setSelectedIndex(null);
|
||||||
if (i.type !== 'separator') {
|
if (i.type !== 'separator') {
|
||||||
i.onSelect?.();
|
i.onSelect?.();
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
import { useMutation } from '@tanstack/react-query';
|
|
||||||
import { invoke } from '@tauri-apps/api/core';
|
import { invoke } from '@tauri-apps/api/core';
|
||||||
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
|
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
export function useCopyAsCurl(requestId: string) {
|
export function useCopyAsCurl(requestId: string) {
|
||||||
return useMutation<string>({
|
const [checked, setChecked] = useState<boolean>(false);
|
||||||
mutationFn: async () => {
|
return [
|
||||||
|
checked,
|
||||||
|
async () => {
|
||||||
const cmd: string = await invoke('cmd_request_to_curl', { requestId });
|
const cmd: string = await invoke('cmd_request_to_curl', { requestId });
|
||||||
await writeText(cmd);
|
await writeText(cmd);
|
||||||
|
setChecked(true);
|
||||||
|
setTimeout(() => setChecked(false), 800);
|
||||||
return cmd;
|
return cmd;
|
||||||
},
|
},
|
||||||
});
|
] as const;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user