|
| 1 | +/** |
| 2 | + * Per-handle public wins profile: /wins/[handle] |
| 3 | + * Aggregates all public wins by a single user, oldest to newest. |
| 4 | + * Shows: 52-week score timeline, total wins, longest streak. |
| 5 | + */ |
| 6 | + |
| 7 | +import Link from "next/link"; |
| 8 | +import { notFound } from "next/navigation"; |
| 9 | +import { ConvexHttpClient } from "convex/browser"; |
| 10 | +import { api } from "../../../../convex/_generated/api"; |
| 11 | +import { ArrowLeft, Flame, TrendingUp, Calendar } from "lucide-react"; |
| 12 | + |
| 13 | +const CONVEX_URL = |
| 14 | + process.env.NEXT_PUBLIC_CONVEX_URL || process.env.CONVEX_URL || ""; |
| 15 | + |
| 16 | +interface PublicWin { |
| 17 | + _id: string; |
| 18 | + productName: string; |
| 19 | + weekNum: number; |
| 20 | + shippingScore: number; |
| 21 | + streak: number; |
| 22 | + tasksCompleted: number; |
| 23 | + tasksTotal: number; |
| 24 | + feedbackCount: number; |
| 25 | + loopkitScore: number | null; |
| 26 | + mrr: number | null; |
| 27 | + oneThing: string; |
| 28 | + createdAt: number; |
| 29 | + handle: string; |
| 30 | + projectSlug: string | null; |
| 31 | +} |
| 32 | + |
| 33 | +async function fetchWinsForHandle(handle: string): Promise<PublicWin[]> { |
| 34 | + if (!CONVEX_URL) return []; |
| 35 | + try { |
| 36 | + const client = new ConvexHttpClient(CONVEX_URL); |
| 37 | + const wins = await client.query(api.milestones.listPublicWins, { limit: 200 }); |
| 38 | + return (wins as PublicWin[]).filter( |
| 39 | + (w) => w.handle.toLowerCase() === handle.toLowerCase(), |
| 40 | + ); |
| 41 | + } catch (err) { |
| 42 | + console.error("Failed to load handle wins:", err); |
| 43 | + return []; |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +export async function generateMetadata({ params }: { params: { handle: string } }) { |
| 48 | + return { |
| 49 | + title: `@${params.handle} — LoopKit Wins`, |
| 50 | + description: `Public shipping wins by @${params.handle} on LoopKit.`, |
| 51 | + }; |
| 52 | +} |
| 53 | + |
| 54 | +function formatDate(ts: number): string { |
| 55 | + return new Date(ts).toISOString().split("T")[0]; |
| 56 | +} |
| 57 | + |
| 58 | +export default async function HandleWinsPage({ |
| 59 | + params, |
| 60 | +}: { |
| 61 | + params: { handle: string }; |
| 62 | +}) { |
| 63 | + const wins = await fetchWinsForHandle(params.handle); |
| 64 | + |
| 65 | + if (wins.length === 0) { |
| 66 | + notFound(); |
| 67 | + } |
| 68 | + |
| 69 | + // Sort oldest to newest |
| 70 | + const sorted = [...wins].sort((a, b) => a.createdAt - b.createdAt); |
| 71 | + const totalWins = sorted.length; |
| 72 | + const longestStreak = sorted.reduce((max, w) => Math.max(max, w.streak), 0); |
| 73 | + const avgScore = Math.round( |
| 74 | + sorted.reduce((s, w) => s + w.shippingScore, 0) / sorted.length, |
| 75 | + ); |
| 76 | + const productName = sorted[sorted.length - 1].productName; |
| 77 | + const firstWin = formatDate(sorted[0].createdAt); |
| 78 | + |
| 79 | + return ( |
| 80 | + <main id="main-content" className="max-w-3xl mx-auto px-6 py-16"> |
| 81 | + <Link |
| 82 | + href="/wins" |
| 83 | + className="inline-flex items-center gap-1.5 text-sm text-zinc-500 hover:text-zinc-300 transition-colors mb-8" |
| 84 | + > |
| 85 | + <ArrowLeft className="h-4 w-4" aria-hidden="true" /> |
| 86 | + All wins |
| 87 | + </Link> |
| 88 | + |
| 89 | + <header className="mb-12"> |
| 90 | + <div className="flex items-baseline gap-2 mb-2"> |
| 91 | + <span className="text-zinc-500 text-sm font-mono">@</span> |
| 92 | + <h1 className="text-3xl font-bold text-white">{params.handle}</h1> |
| 93 | + </div> |
| 94 | + <p className="text-zinc-400 text-sm"> |
| 95 | + Shipping <span className="text-white font-medium">{productName}</span>{" "} |
| 96 | + since {firstWin}. |
| 97 | + </p> |
| 98 | + |
| 99 | + <dl className="mt-6 grid grid-cols-3 gap-3"> |
| 100 | + <div className="p-4 rounded-xl border border-zinc-800 bg-zinc-900/30"> |
| 101 | + <dt className="text-xs text-zinc-500 uppercase tracking-wider">Wins</dt> |
| 102 | + <dd className="mt-1 text-2xl font-bold text-white">{totalWins}</dd> |
| 103 | + </div> |
| 104 | + <div className="p-4 rounded-xl border border-orange-500/20 bg-zinc-900/30"> |
| 105 | + <dt className="text-xs text-orange-400 uppercase tracking-wider flex items-center gap-1"> |
| 106 | + <Flame className="h-3 w-3" /> Longest |
| 107 | + </dt> |
| 108 | + <dd className="mt-1 text-2xl font-bold text-white">{longestStreak}</dd> |
| 109 | + </div> |
| 110 | + <div className="p-4 rounded-xl border border-zinc-800 bg-zinc-900/30"> |
| 111 | + <dt className="text-xs text-zinc-500 uppercase tracking-wider">Avg</dt> |
| 112 | + <dd className="mt-1 text-2xl font-bold text-white">{avgScore}%</dd> |
| 113 | + </div> |
| 114 | + </dl> |
| 115 | + </header> |
| 116 | + |
| 117 | + <section> |
| 118 | + <h2 className="text-sm font-medium text-zinc-400 mb-4 flex items-center gap-2"> |
| 119 | + <Calendar className="h-4 w-4" aria-hidden="true" /> |
| 120 | + Timeline |
| 121 | + </h2> |
| 122 | + |
| 123 | + <ol className="relative space-y-6 border-l border-zinc-800 pl-6 ml-2"> |
| 124 | + {sorted.map((win) => ( |
| 125 | + <li key={win._id} className="relative"> |
| 126 | + <span className="absolute -left-[31px] top-1 w-3 h-3 rounded-full bg-violet-500 ring-4 ring-zinc-950" /> |
| 127 | + <div className="p-4 rounded-xl border border-zinc-800 bg-zinc-900/30"> |
| 128 | + <div className="flex items-center justify-between mb-2"> |
| 129 | + <div className="text-xs text-zinc-500 font-mono"> |
| 130 | + Week {win.weekNum} · {formatDate(win.createdAt)} |
| 131 | + </div> |
| 132 | + <div className="flex items-center gap-2 text-xs"> |
| 133 | + {win.streak >= 4 && ( |
| 134 | + <span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-full border border-orange-500/30 bg-orange-500/10 text-orange-400"> |
| 135 | + <Flame className="h-3 w-3" /> |
| 136 | + {win.streak} |
| 137 | + </span> |
| 138 | + )} |
| 139 | + <span className="inline-flex items-center gap-1 text-emerald-400"> |
| 140 | + <TrendingUp className="h-3 w-3" /> |
| 141 | + {win.shippingScore}% |
| 142 | + </span> |
| 143 | + </div> |
| 144 | + </div> |
| 145 | + <p className="text-sm text-zinc-300 italic"> |
| 146 | + “{win.oneThing}” |
| 147 | + </p> |
| 148 | + </div> |
| 149 | + </li> |
| 150 | + ))} |
| 151 | + </ol> |
| 152 | + </section> |
| 153 | + </main> |
| 154 | + ); |
| 155 | +} |
0 commit comments