mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-17 23:13:51 +01:00
Better curl import
This commit is contained in:
27
src-web/hooks/useCopy.ts
Normal file
27
src-web/hooks/useCopy.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { clear, writeText } from '@tauri-apps/plugin-clipboard-manager';
|
||||
import { useCallback } from 'react';
|
||||
import { useToast } from '../components/ToastContext';
|
||||
|
||||
export function useCopy({ disableToast }: { disableToast?: boolean } = {}) {
|
||||
const toast = useToast();
|
||||
|
||||
const copy = useCallback(
|
||||
(text: string | null) => {
|
||||
if (text == null) {
|
||||
clear().catch(console.error);
|
||||
} else {
|
||||
writeText(text).catch(console.error);
|
||||
}
|
||||
if (text != '' && !disableToast) {
|
||||
toast.show({
|
||||
id: 'copied',
|
||||
variant: 'copied',
|
||||
message: 'Copied to clipboard',
|
||||
});
|
||||
}
|
||||
},
|
||||
[disableToast, toast],
|
||||
);
|
||||
|
||||
return copy;
|
||||
}
|
||||
Reference in New Issue
Block a user