diff --git a/src/app/models/[slug]/page.tsx b/src/app/models/[slug]/page.tsx index 0c7f0bf..c52a2e8 100644 --- a/src/app/models/[slug]/page.tsx +++ b/src/app/models/[slug]/page.tsx @@ -7,6 +7,7 @@ import { formatPrice, formatContextWindow, formatBenchmark, getBenchmarkColor, c import { ReviewSection } from "@/components/models/ReviewSection"; import { ModelDetailSkeleton } from "@/components/ui/Skeletons"; import { Model } from "@/types"; +import { ShareButton } from "@/components/ui/ShareButton"; export default function ModelDetailPage() { const params = useParams(); @@ -86,20 +87,24 @@ export default function ModelDetailPage() {
by{" "} diff --git a/src/components/ui/ShareButton.tsx b/src/components/ui/ShareButton.tsx new file mode 100644 index 0000000..e8ed932 --- /dev/null +++ b/src/components/ui/ShareButton.tsx @@ -0,0 +1,58 @@ +"use client"; + +import { useState } from "react"; +import { Share2 } from "lucide-react"; +import { cn } from "@/lib/utils"; + +interface ShareButtonProps { + title: string; + className?: string; +} + +export function ShareButton({ title, className }: ShareButtonProps) { + const [copied, setCopied] = useState(false); + + const handleShare = async () => { + const url = window.location.href; + + try { + const isMobile = + /Android|iPhone|iPad|iPod/i.test(navigator.userAgent); + + if (isMobile && navigator.share) { + await navigator.share({ + title, + url, + }); + return; + } + + await navigator.clipboard.writeText(url); + + setCopied(true); + + setTimeout(() => { + setCopied(false); + }, 1500); + } catch (err) { + console.error("Share failed", err); + } +}; + + return ( + + ); +} \ No newline at end of file