mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-20 16:43:53 +01:00
Fade in window contents (Layout)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { readText, writeText } from '@tauri-apps/plugin-clipboard-manager';
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { useToast } from '../components/ToastContext';
|
||||
import { useWindowFocus } from './useWindowFocus';
|
||||
import { createGlobalState } from 'react-use';
|
||||
|
||||
@@ -8,6 +9,7 @@ const useClipboardTextState = createGlobalState<string>('');
|
||||
export function useClipboardText() {
|
||||
const [value, setValue] = useClipboardTextState();
|
||||
const focused = useWindowFocus();
|
||||
const toast = useToast();
|
||||
|
||||
useEffect(() => {
|
||||
readText().then(setValue);
|
||||
@@ -16,9 +18,14 @@ export function useClipboardText() {
|
||||
const setText = useCallback(
|
||||
(text: string) => {
|
||||
writeText(text).catch(console.error);
|
||||
toast.show({
|
||||
id: 'copied',
|
||||
variant: 'copied',
|
||||
message: 'Copied to clipboard',
|
||||
});
|
||||
setValue(text);
|
||||
},
|
||||
[setValue],
|
||||
[setValue, toast],
|
||||
);
|
||||
|
||||
return [value, setText] as const;
|
||||
|
||||
@@ -1,23 +1,11 @@
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
|
||||
import { useState } from 'react';
|
||||
import { useToast } from '../components/ToastContext';
|
||||
import { useClipboardText } from './useClipboardText';
|
||||
|
||||
export function useCopyAsCurl(requestId: string) {
|
||||
const [checked, setChecked] = useState<boolean>(false);
|
||||
const toast = useToast();
|
||||
return [
|
||||
checked,
|
||||
async () => {
|
||||
const cmd: string = await invoke('cmd_request_to_curl', { requestId });
|
||||
await writeText(cmd);
|
||||
setChecked(true);
|
||||
setTimeout(() => setChecked(false), 800);
|
||||
toast.show({
|
||||
variant: 'copied',
|
||||
message: 'Curl copied to clipboard',
|
||||
});
|
||||
return cmd;
|
||||
},
|
||||
] as const;
|
||||
const [, copy] = useClipboardText();
|
||||
return async () => {
|
||||
const cmd: string = await invoke('cmd_request_to_curl', { requestId });
|
||||
copy(cmd);
|
||||
return cmd;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user