chore: use copy-to-clipboard (#43)

This commit is contained in:
boojack
2023-04-20 10:40:48 +08:00
committed by GitHub
parent 4abe81f351
commit c1e5957038
3 changed files with 7 additions and 7 deletions

View File

@ -19,6 +19,7 @@
"@radix-ui/react-tooltip": "^1.0.5",
"@vercel/analytics": "^0.1.11",
"axios": "^1.3.4",
"copy-to-clipboard": "^3.3.3",
"csstype": "^3.1.1",
"dayjs": "^1.11.7",
"eventsource-parser": "^1.0.0",

3
pnpm-lock.yaml generated
View File

@ -31,6 +31,9 @@ dependencies:
axios:
specifier: ^1.3.4
version: 1.3.4
copy-to-clipboard:
specifier: ^3.3.3
version: 3.3.3
csstype:
specifier: ^3.1.1
version: 3.1.1

View File

@ -1,3 +1,4 @@
import copy from "copy-to-clipboard";
import { toast } from "react-hot-toast";
import { useTranslation } from "react-i18next";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
@ -23,13 +24,8 @@ export const CodeBlock = (props: Props) => {
const showExecuteButton = currentConnectionCtx?.connection && currentConnectionCtx?.database && language.toUpperCase() === "SQL";
const copyToClipboard = () => {
if (!navigator.clipboard || !navigator.clipboard.writeText) {
toast.error("Failed to copy to clipboard");
return;
}
navigator.clipboard.writeText(value).then(() => {
toast.success("Copied to clipboard");
});
copy(value);
toast.success("Copied to clipboard");
};
const handleExecuteQuery = () => {