mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-19 16:21:13 +01:00
Better curl import
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useClipboardText } from '../hooks/useClipboardText';
|
||||
import { useCopy } from '../hooks/useCopy';
|
||||
import { useTimedBoolean } from '../hooks/useTimedBoolean';
|
||||
import type { ButtonProps } from './core/Button';
|
||||
import { Button } from './core/Button';
|
||||
@@ -8,7 +8,7 @@ interface Props extends ButtonProps {
|
||||
}
|
||||
|
||||
export function CopyButton({ text, ...props }: Props) {
|
||||
const [, copy] = useClipboardText({ disableToast: true });
|
||||
const copy = useCopy({ disableToast: true });
|
||||
const [copied, setCopied] = useTimedBoolean();
|
||||
return (
|
||||
<Button
|
||||
|
||||
@@ -3,9 +3,8 @@ import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow';
|
||||
import type { Model } from '@yaakapp/api';
|
||||
import { useEffect } from 'react';
|
||||
import { useAtiveWorkspaceChangedToast } from '../hooks/useAtiveWorkspaceChangedToast';
|
||||
import { useClipboardText } from '../hooks/useClipboardText';
|
||||
import { useToggleCommandPalette } from '../hooks/useToggleCommandPalette';
|
||||
import { cookieJarsQueryKey } from '../hooks/useCookieJars';
|
||||
import { useCopy } from '../hooks/useCopy';
|
||||
import { environmentsQueryKey } from '../hooks/useEnvironments';
|
||||
import { foldersQueryKey } from '../hooks/useFolders';
|
||||
import { grpcConnectionsQueryKey } from '../hooks/useGrpcConnections';
|
||||
@@ -23,6 +22,7 @@ import { useRecentWorkspaces } from '../hooks/useRecentWorkspaces';
|
||||
import { useRequestUpdateKey } from '../hooks/useRequestUpdateKey';
|
||||
import { settingsQueryKey, useSettings } from '../hooks/useSettings';
|
||||
import { useSyncThemeToDocument } from '../hooks/useSyncThemeToDocument';
|
||||
import { useToggleCommandPalette } from '../hooks/useToggleCommandPalette';
|
||||
import { workspacesQueryKey } from '../hooks/useWorkspaces';
|
||||
import { useZoom } from '../hooks/useZoom';
|
||||
import { modelsEq } from '../lib/models';
|
||||
@@ -159,7 +159,7 @@ export function GlobalHooks() {
|
||||
useHotKey('app.zoom_reset', () => zoom.zoomReset);
|
||||
useListenToTauriEvent('zoom_reset', () => zoom.zoomReset);
|
||||
|
||||
const [, copy] = useClipboardText();
|
||||
const copy = useCopy();
|
||||
useListenToTauriEvent('generate_theme_css', () => {
|
||||
const themesCss = [
|
||||
yaakDark,
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
import { clear, readText } from '@tauri-apps/plugin-clipboard-manager';
|
||||
import { motion } from 'framer-motion';
|
||||
import React, { useState } from 'react';
|
||||
import { useClipboardText } from '../hooks/useClipboardText';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useImportCurl } from '../hooks/useImportCurl';
|
||||
import { useWindowFocus } from '../hooks/useWindowFocus';
|
||||
import { Button } from './core/Button';
|
||||
import { Icon } from './core/Icon';
|
||||
|
||||
export function ImportCurlButton() {
|
||||
const [clipboardText] = useClipboardText();
|
||||
const importCurl = useImportCurl({ clearClipboard: true });
|
||||
const focused = useWindowFocus();
|
||||
const [clipboardText, setClipboardText] = useState('');
|
||||
|
||||
const importCurl = useImportCurl();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
readText().then(setClipboardText);
|
||||
}, [focused]);
|
||||
|
||||
if (!clipboardText?.trim().startsWith('curl ')) {
|
||||
return null;
|
||||
}
|
||||
@@ -26,14 +33,17 @@ export function ImportCurlButton() {
|
||||
color="primary"
|
||||
leftSlot={<Icon icon="paste" size="sm" />}
|
||||
isLoading={isLoading}
|
||||
onClick={() => {
|
||||
onClick={async () => {
|
||||
setIsLoading(true);
|
||||
importCurl
|
||||
.mutateAsync({
|
||||
requestId: null, // Create request
|
||||
command: clipboardText,
|
||||
})
|
||||
.finally(() => setIsLoading(false));
|
||||
try {
|
||||
await importCurl.mutateAsync({ command: clipboardText });
|
||||
await clear(); // Clear the clipboard so the button goes away
|
||||
setClipboardText('');
|
||||
} catch (e) {
|
||||
// Nothing
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Import Curl
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import type { HttpRequest, HttpRequestHeader, HttpUrlParameter } from '@yaakapp/api';
|
||||
import classNames from 'classnames';
|
||||
import type { CSSProperties } from 'react';
|
||||
import React, { memo, useCallback, useMemo, useState } from 'react';
|
||||
@@ -12,7 +13,6 @@ import { useRequestUpdateKey } from '../hooks/useRequestUpdateKey';
|
||||
import { useSendAnyHttpRequest } from '../hooks/useSendAnyHttpRequest';
|
||||
import { useUpdateAnyHttpRequest } from '../hooks/useUpdateAnyHttpRequest';
|
||||
import { tryFormatJson } from '../lib/formatters';
|
||||
import type { HttpRequest, HttpRequestHeader, HttpUrlParameter } from '@yaakapp/api';
|
||||
import {
|
||||
AUTH_TYPE_BASIC,
|
||||
AUTH_TYPE_BEARER,
|
||||
@@ -268,7 +268,7 @@ export const RequestPane = memo(function RequestPane({
|
||||
|
||||
const isLoading = useIsResponseLoading(activeRequestId ?? null);
|
||||
const { updateKey } = useRequestUpdateKey(activeRequestId ?? null);
|
||||
const importCurl = useImportCurl({ clearClipboard: true });
|
||||
const importCurl = useImportCurl();
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -282,11 +282,11 @@ export const RequestPane = memo(function RequestPane({
|
||||
url={activeRequest.url}
|
||||
method={activeRequest.method}
|
||||
placeholder="https://example.com"
|
||||
onPaste={async (command) => {
|
||||
onPaste={(command) => {
|
||||
if (!command.startsWith('curl ')) {
|
||||
return;
|
||||
}
|
||||
importCurl.mutate({ requestId: activeRequestId, command });
|
||||
importCurl.mutate({ overwriteRequestId: activeRequestId, command });
|
||||
}}
|
||||
autocomplete={{
|
||||
minMatch: 3,
|
||||
|
||||
Reference in New Issue
Block a user