diff --git a/src/components/ProfileShareCard.tsx b/src/components/ProfileShareCard.tsx new file mode 100644 index 00000000..18989061 --- /dev/null +++ b/src/components/ProfileShareCard.tsx @@ -0,0 +1,38 @@ +interface ProfileShareCardProps { + username: string; + streak: number; + profileUrl: string; +} + +export default function ProfileShareCard({ + username, + streak, + profileUrl, +}: ProfileShareCardProps) { + return ( +
+
+

{username}

+ +
+ 🔥 +
+ +

+ {streak}-Day Streak +

+ +

+ {profileUrl} +

+ +
+ DevTrack +
+
+
+ ); +} \ No newline at end of file diff --git a/src/components/ShareProfileSection.tsx b/src/components/ShareProfileSection.tsx index adf9e00f..b7fd63b8 100644 --- a/src/components/ShareProfileSection.tsx +++ b/src/components/ShareProfileSection.tsx @@ -1,8 +1,10 @@ "use client"; -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { toast } from "sonner"; import CopyLinkButton from "@/components/CopyLinkButton"; +import { toPng } from "html-to-image"; +import ProfileShareCard from "./ProfileShareCard"; interface ShareProfileSectionProps { username: string; @@ -16,6 +18,8 @@ export default function ShareProfileSection({ profileUrl, }: ShareProfileSectionProps) { const [canUseNativeShare, setCanUseNativeShare] = useState(false); + const cardRef = useRef(null); + const [showPreview, setShowPreview] = useState(false); useEffect(() => { setCanUseNativeShare( @@ -46,9 +50,25 @@ export default function ShareProfileSection({ } } }; + + const downloadCard = async () => { + if (!cardRef.current) return; + + try { + const dataUrl = await toPng(cardRef.current); + + const link = document.createElement("a"); + link.download = `${username}-devtrack-card.png`; + link.href = dataUrl; + link.click(); + } catch { + toast.error("Failed to download card"); + } + }; - return ( -
+return ( + <> +

@@ -59,44 +79,80 @@ export default function ShareProfileSection({

+ +
{canUseNativeShare ? ( ) : null} - + - + 𝕏 X - + - + in LinkedIn - +
- ); + + {showPreview && ( +
+
+ +
+ +
+ + + +
+
+ )} + +); } \ No newline at end of file