+ {description} +
+ )} +diff --git a/client/src/components/ResourceLinkView.tsx b/client/src/components/ResourceLinkView.tsx new file mode 100644 index 00000000..94fce429 --- /dev/null +++ b/client/src/components/ResourceLinkView.tsx @@ -0,0 +1,104 @@ +import { useState, useCallback, useEffect } from "react"; +import { Copy, CheckCheck } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { useToast } from "@/lib/hooks/useToast"; + +interface ResourceLinkViewProps { + uri: string; + name?: string; + description?: string; + mimeType?: string; +} + +const ResourceLinkView = ({ + uri, + name, + description, + mimeType, +}: ResourceLinkViewProps) => { + const { toast } = useToast(); + const [copied, setCopied] = useState(false); + + useEffect(() => { + let timeoutId: NodeJS.Timeout; + if (copied) { + timeoutId = setTimeout(() => { + setCopied(false); + }, 500); + } + return () => { + if (timeoutId) { + clearTimeout(timeoutId); + } + }; + }, [copied]); + + const handleCopyUri = useCallback(() => { + try { + navigator.clipboard.writeText(uri); + setCopied(true); + } catch (error) { + toast({ + title: "Error", + description: `There was an error copying URI to clipboard: ${error instanceof Error ? error.message : String(error)}`, + variant: "destructive", + }); + } + }, [uri, toast]); + + const displayName = name || new URL(uri).pathname.split("/").pop() || uri; + + return ( +
+ {description} +
+ )} +