Spaces:
Sleeping
Sleeping
Download src/components/share-menu.tsx from veltrixcode/Iot: direct link, hf CLI and curl.
- Browser
- Download file 6.39 kB
-
https://huggingface.co/spaces/veltrixcode/Iot/resolve/main/src/components/share-menu.tsx
- Command line
-
hf download hf://spaces/veltrixcode/Iot/src/components/share-menu.tsx
-
curl -L -o share-menu.tsx https://huggingface.co/spaces/veltrixcode/Iot/resolve/main/src/components/share-menu.tsx
6.39 kB
| "use client" | |
| import { | |
| Popover, | |
| PopoverContent, | |
| PopoverTrigger, | |
| } from "@/components/ui/popover" | |
| import { Button } from "@/components/ui/button" | |
| import { Share2, Copy, Check, Twitter, Facebook, Linkedin, Link as LinkIcon, MessageSquare, MessageCircle, Send, Gamepad2 } from "lucide-react" | |
| import { useState } from "react" | |
| import { cn } from "@/lib/utils" | |
| interface ShareMenuProps { | |
| artworkId: string | |
| prompt: string | |
| trigger?: React.ReactNode | |
| className?: string | |
| } | |
| export function ShareMenu({ artworkId, prompt, trigger, className }: ShareMenuProps) { | |
| const [copied, setCopied] = useState(false) | |
| const [isOpen, setIsOpen] = useState(false) | |
| // Base URL needed for client-side composition | |
| // Fallback to window.location if available logic to prevent SSR issues | |
| const baseUrl = typeof window !== "undefined" ? window.location.origin : "" | |
| const shareUrl = `${baseUrl}/artwork/${artworkId}` | |
| const encodedUrl = encodeURIComponent(shareUrl) | |
| const encodedText = encodeURIComponent(`Check out this AI art: "${prompt}" created on Imyra!`) | |
| const handleCopy = async () => { | |
| try { | |
| await navigator.clipboard.writeText(shareUrl) | |
| setCopied(true) | |
| setTimeout(() => setCopied(false), 2000) | |
| } catch (err) { | |
| console.error("Failed to copy", err) | |
| } | |
| } | |
| const shareLinks = [ | |
| { | |
| name: "Twitter / X", | |
| icon: Twitter, | |
| url: `https://twitter.com/intent/tweet?text=${encodedText}&url=${encodedUrl}`, | |
| color: "hover:text-blue-400" | |
| }, | |
| { | |
| name: "Facebook", | |
| icon: Facebook, | |
| url: `https://www.facebook.com/sharer/sharer.php?u=${encodedUrl}`, | |
| color: "hover:text-blue-600" | |
| }, | |
| { | |
| name: "WhatsApp", | |
| icon: MessageCircle, | |
| url: `https://wa.me/?text=${encodedText}%20${encodedUrl}`, | |
| color: "hover:text-green-500" | |
| }, | |
| { | |
| name: "Telegram", | |
| icon: Send, | |
| url: `https://t.me/share/url?url=${encodedUrl}&text=${encodedText}`, | |
| color: "hover:text-blue-500" | |
| }, | |
| { | |
| name: "Discord", | |
| icon: Gamepad2, | |
| url: "", // Discord doesn't have a share URL, handled via onClick | |
| action: true, // Special flag to trigger copy | |
| color: "hover:text-indigo-500" | |
| }, | |
| { | |
| name: "Reddit", | |
| icon: MessageSquare, | |
| url: `https://www.reddit.com/submit?url=${encodedUrl}&title=${encodedText}`, | |
| color: "hover:text-orange-500" | |
| }, | |
| { | |
| name: "LinkedIn", | |
| icon: Linkedin, | |
| url: `https://www.linkedin.com/sharing/share-offsite/?url=${encodedUrl}`, | |
| color: "hover:text-blue-700" | |
| } | |
| ] | |
| return ( | |
| <Popover open={isOpen} onOpenChange={setIsOpen}> | |
| <PopoverTrigger asChild> | |
| {trigger || ( | |
| <Button variant="outline" className={cn("neo-brutalist", className)}> | |
| <Share2 className="mr-2 h-4 w-4" /> Share | |
| </Button> | |
| )} | |
| </PopoverTrigger> | |
| <PopoverContent align="end" className="w-80 glass-panel border-2 p-0 overflow-hidden"> | |
| <div className="p-4 border-b border-border/50 bg-background/50"> | |
| <h4 className="font-bold text-sm mb-3">Share Artwork</h4> | |
| <div className="flex items-center gap-2"> | |
| <div className="flex-1 h-9 bg-secondary/10 border border-input rounded-md px-3 text-xs flex items-center text-muted-foreground truncate font-mono"> | |
| {shareUrl} | |
| </div> | |
| <Button | |
| size="icon" | |
| variant="secondary" | |
| className="h-9 w-9 shrink-0" | |
| onClick={handleCopy} | |
| > | |
| {copied ? <Check className="h-4 w-4 text-green-500" /> : <Copy className="h-4 w-4" />} | |
| <span className="sr-only">Copy link</span> | |
| </Button> | |
| </div> | |
| </div> | |
| <div className="p-2 grid grid-cols-2 gap-1 bg-background/80"> | |
| {shareLinks.map((platform) => { | |
| if (platform.action) { | |
| return ( | |
| <button | |
| key={platform.name} | |
| onClick={() => { | |
| handleCopy() | |
| // Optional: You could show a specialized toast here | |
| }} | |
| className={cn( | |
| "flex items-center gap-3 px-3 py-2.5 text-sm font-medium rounded-md transition-colors hover:bg-secondary/20 w-full text-left", | |
| platform.color | |
| )} | |
| > | |
| <platform.icon className="h-4 w-4" /> | |
| {platform.name} | |
| </button> | |
| ) | |
| } | |
| return ( | |
| <a | |
| key={platform.name} | |
| href={platform.url} | |
| target="_blank" | |
| rel="noopener noreferrer" | |
| className={cn( | |
| "flex items-center gap-3 px-3 py-2.5 text-sm font-medium rounded-md transition-colors hover:bg-secondary/20", | |
| platform.color | |
| )} | |
| onClick={() => setIsOpen(false)} | |
| > | |
| <platform.icon className="h-4 w-4" /> | |
| {platform.name} | |
| </a> | |
| ) | |
| })} | |
| </div> | |
| </PopoverContent> | |
| </Popover> | |
| ) | |
| } | |