Skip to content

Commit 2a099f9

Browse files
committed
Add website copy button
1 parent 0700b7c commit 2a099f9

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

apps/web/src/components/websites/SnippetModal.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState } from "react";
22
import { Button, Modal } from "@heroui/react";
33
import { HugeiconsIcon } from "@hugeicons/react";
4-
import { CodeIcon } from "@hugeicons/core-free-icons";
4+
import { CodeIcon, CopyIcon, Tick02Icon } from "@hugeicons/core-free-icons";
55
import type { Website } from "@/lib/api";
66

77
interface Props {
@@ -11,6 +11,7 @@ interface Props {
1111

1212
export default function SnippetModal({ website, onClose }: Props) {
1313
const [copied, setCopied] = useState(false);
14+
const [copiedId, setCopiedId] = useState<string | null>(null);
1415

1516
const snippet = `<script defer src="${window.location.origin}/t.js" data-website="${website?.id}"></script>`;
1617

@@ -20,6 +21,13 @@ export default function SnippetModal({ website, onClose }: Props) {
2021
setTimeout(() => setCopied(false), 2000);
2122
}
2223

24+
function handleCopyId() {
25+
navigator.clipboard.writeText(website?.id ?? "");
26+
setCopiedId(website?.id ?? null);
27+
setTimeout(() => setCopiedId(null), 2000);
28+
}
29+
30+
2331
return (
2432
<Modal
2533
isOpen={!!website}
@@ -47,6 +55,15 @@ export default function SnippetModal({ website, onClose }: Props) {
4755
<pre className="bg-default rounded-xl p-4 text-xs font-mono text-foreground overflow-x-auto select-all">
4856
{snippet}
4957
</pre>
58+
59+
<p className="mt-4 text-xs text-muted items-center inline-flex">
60+
{website?.id}
61+
<HugeiconsIcon
62+
onClick={handleCopyId}
63+
icon={
64+
copiedId === website?.id ? Tick02Icon : CopyIcon}
65+
className="w-4 h-4 ml-2" />
66+
</p>
5067
</Modal.Body>
5168
<Modal.Footer>
5269
<Button variant="outline" onPress={onClose} className="flex-1">

apps/web/src/components/websites/WebsiteCard.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
Delete02Icon,
66
PencilEdit01Icon,
77
ArrowRight01Icon,
8-
CodeSquareIcon,
8+
CodeSimpleIcon,
99
} from "@hugeicons/core-free-icons";
1010
import type { Website } from "@/lib/api";
1111
import WebsiteLiveCount from "./WebsiteLiveCount";
@@ -38,14 +38,15 @@ export default function WebsiteCard({ website, onSnippet, onEdit, onDelete }: Pr
3838
{website.url && <span>{website.url}</span>}
3939
</Card.Description>
4040
</div>
41-
<div className="flex items-center gap-3 ml-3 shrink-0">
41+
<div className="flex items-center ml-3 shrink-0">
4242
<WebsiteLiveCount websiteId={website.id} />
43+
<div className="w-4"/>
4344
<Button
4445
variant="ghost"
4546
className="text-muted hover:text-foreground"
4647
onPress={() => onSnippet(website)}
4748
>
48-
<HugeiconsIcon icon={CodeSquareIcon} size={16} />
49+
<HugeiconsIcon icon={CodeSimpleIcon} size={16} />
4950
</Button>
5051
<Button
5152
variant="ghost"

0 commit comments

Comments
 (0)