aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/components/dashboard/settings/AddApiKey.tsx
diff options
context:
space:
mode:
authorkamtschatka <sschatka@gmail.com>2024-06-09 15:30:56 +0200
committerGitHub <noreply@github.com>2024-06-09 14:30:56 +0100
commitbe1bb388924f4422058099dcb0debdd1c857d36a (patch)
treebd518e1df0a137f88950b4f7f083da90e8e29cbb /apps/web/components/dashboard/settings/AddApiKey.tsx
parentf7a77533240ec435c8a7b103b6f6be409bf995d8 (diff)
downloadkarakeep-be1bb388924f4422058099dcb0debdd1c857d36a.tar.zst
feature(web): Add syntax highlighting to code blocks and a quick copy button. Fixes #195 (#197)
* Any plans to support copy to clipboard (markdown code) for notes? #195 added a button to copy the markdown and added code highlighting * Any plans to support copy to clipboard (markdown code) for notes? #195 Changed the copy-button to a generic one added a safeguard and a message to the copy button if copying is not possible * Some code cleanups --------- Co-authored-by: kamtschatka <simon.schatka@gmx.at> Co-authored-by: MohamedBassem <me@mbassem.com>
Diffstat (limited to 'apps/web/components/dashboard/settings/AddApiKey.tsx')
-rw-r--r--apps/web/components/dashboard/settings/AddApiKey.tsx22
1 files changed, 6 insertions, 16 deletions
diff --git a/apps/web/components/dashboard/settings/AddApiKey.tsx b/apps/web/components/dashboard/settings/AddApiKey.tsx
index 15a78d56..34fd2df7 100644
--- a/apps/web/components/dashboard/settings/AddApiKey.tsx
+++ b/apps/web/components/dashboard/settings/AddApiKey.tsx
@@ -5,6 +5,7 @@ import { useState } from "react";
import { useRouter } from "next/navigation";
import { ActionButton } from "@/components/ui/action-button";
import { Button } from "@/components/ui/button";
+import CopyBtn from "@/components/ui/copy-button";
import {
Dialog,
DialogClose,
@@ -28,19 +29,10 @@ import { Input } from "@/components/ui/input";
import { toast } from "@/components/ui/use-toast";
import { api } from "@/lib/trpc";
import { zodResolver } from "@hookform/resolvers/zod";
-import { Check, Copy } from "lucide-react";
import { useForm } from "react-hook-form";
import { z } from "zod";
function ApiKeySuccess({ apiKey }: { apiKey: string }) {
- const [isCopied, setCopied] = useState(false);
-
- const onCopy = () => {
- navigator.clipboard.writeText(apiKey);
- setCopied(true);
- setTimeout(() => setCopied(false), 2000);
- };
-
return (
<div>
<div className="py-4">
@@ -49,13 +41,11 @@ function ApiKeySuccess({ apiKey }: { apiKey: string }) {
</div>
<div className="flex space-x-2 pt-2">
<Input value={apiKey} readOnly />
- <Button onClick={onCopy}>
- {!isCopied ? (
- <Copy className="size-4" />
- ) : (
- <Check className="size-4" />
- )}
- </Button>
+ <CopyBtn
+ getStringToCopy={() => {
+ return apiKey;
+ }}
+ />
</div>
</div>
);