|
'use client' |
|
import { useState } from 'react' |
|
import { Share, Copy } from 'lucide-react' |
|
import { Button } from '@/components/ui/button' |
|
import { Input } from '@/components/ui/input' |
|
import { |
|
Popover, |
|
PopoverContent, |
|
PopoverTrigger, |
|
} from '@/components/ui/popover' |
|
|
|
export function SharePopover() { |
|
const [copied, setCopied] = useState(false) |
|
const url = typeof window !== 'undefined' ? window.location.href : '' |
|
|
|
const handleCopy = () => { |
|
navigator.clipboard.writeText(url) |
|
setCopied(true) |
|
setTimeout(() => setCopied(false), 2000) |
|
} |
|
|
|
return ( |
|
<Popover> |
|
<PopoverTrigger asChild> |
|
<Button variant="ghost" size="icon"> |
|
<Share className="h-5 w-5" /> |
|
</Button> |
|
</PopoverTrigger> |
|
<PopoverContent className="w-80"> |
|
<div className="space-y-2"> |
|
<h3 className="font-medium">Share this conversation</h3> |
|
<div className="flex space-x-2"> |
|
<Input value={url} readOnly /> |
|
<Button size="icon" onClick={handleCopy}> |
|
<Copy className="h-4 w-4" /> |
|
</Button> |
|
</div> |
|
{copied && <p className="text-sm text-green-500">Copied to clipboard!</p>} |
|
</div> |
|
</PopoverContent> |
|
</Popover> |
|
) |
|
} |
|
|
|
|