11import { useState } from "react" ;
22import { Button , Modal } from "@heroui/react" ;
33import { HugeiconsIcon } from "@hugeicons/react" ;
4- import { CodeIcon } from "@hugeicons/core-free-icons" ;
4+ import { CodeIcon , CopyIcon , Tick02Icon } from "@hugeicons/core-free-icons" ;
55import type { Website } from "@/lib/api" ;
66
77interface Props {
@@ -11,6 +11,7 @@ interface Props {
1111
1212export 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" >
0 commit comments