|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | 3 | /** |
4 | | - * "What's new" dialog, shown once per update to every signed-in user. After a build is deployed, |
5 | | - * the API serves the release notes for everything that changed since the build the user last |
6 | | - * acknowledged; dismissing it records the current build so it never reappears for that version. |
| 4 | + * "What's new" dialog, shown once per update to every signed-in user. The API serves the changes |
| 5 | + * since the build the user last acknowledged, parsed from the commit messages into structured |
| 6 | + * entries; dismissing it records the current build so it never reappears for that version. |
7 | 7 | * |
8 | | - * The notes are Markdown built from the commit messages, rendered with the same pipeline as the |
9 | | - * in-app document viewer. |
| 8 | + * Design: sober "release notes" — no decorative icon. Each entry shows an icon derived from the |
| 9 | + * commit's conventional-commit type (feat/fix/…), a clean title, and its long-form body tucked |
| 10 | + * behind a "Details" toggle (commit bodies are verbose, so they stay collapsed by default). |
10 | 11 | */ |
11 | 12 | import { useEffect, useState } from 'react'; |
12 | 13 | import { createPortal } from 'react-dom'; |
13 | 14 | import Markdown from 'react-markdown'; |
14 | 15 | import remarkGfm from 'remark-gfm'; |
15 | | -import { Sparkles, X } from 'lucide-react'; |
| 16 | +import { Check, Wrench, Zap, BookOpen, ChevronDown, X, type LucideIcon } from 'lucide-react'; |
16 | 17 | import { api } from '@/lib/api'; |
17 | 18 | import { useAuth } from '@/lib/auth'; |
18 | 19 | import { useT } from '@/lib/i18n'; |
19 | 20 |
|
| 21 | +interface ChangelogEntry { |
| 22 | + type: string | null; |
| 23 | + title: string; |
| 24 | + body: string; |
| 25 | +} |
20 | 26 | interface WhatsNew { |
21 | 27 | show: boolean; |
22 | 28 | version?: string; |
23 | | - notes?: string; |
| 29 | + entries?: ChangelogEntry[]; |
24 | 30 | count?: number; |
25 | 31 | } |
26 | 32 |
|
| 33 | +// Map a conventional-commit type to a small, meaningful icon + tint. Anything unrecognised gets a |
| 34 | +// neutral dot, so the list stays calm rather than noisy. |
| 35 | +const TYPE_STYLE: Record<string, { icon: LucideIcon; cls: string }> = { |
| 36 | + feat: { icon: Check, cls: 'bg-violet-500/15 text-violet-300' }, |
| 37 | + fix: { icon: Wrench, cls: 'bg-amber-500/15 text-amber-300' }, |
| 38 | + perf: { icon: Zap, cls: 'bg-sky-500/15 text-sky-300' }, |
| 39 | + docs: { icon: BookOpen, cls: 'bg-white/[0.06] text-zinc-300' }, |
| 40 | +}; |
| 41 | + |
| 42 | +function EntryRow({ e }: { e: ChangelogEntry }) { |
| 43 | + const { t } = useT(); |
| 44 | + const [open, setOpen] = useState(false); |
| 45 | + const style = e.type ? TYPE_STYLE[e.type] : undefined; |
| 46 | + const Icon = style?.icon; |
| 47 | + |
| 48 | + return ( |
| 49 | + <li className="flex gap-3"> |
| 50 | + <span className={`mt-0.5 grid h-6 w-6 shrink-0 place-items-center rounded-md ${style?.cls ?? 'text-zinc-600'}`}> |
| 51 | + {Icon ? <Icon size={14} /> : <span className="h-1.5 w-1.5 rounded-full bg-zinc-600" />} |
| 52 | + </span> |
| 53 | + <div className="min-w-0 flex-1"> |
| 54 | + <div className="flex items-start justify-between gap-2"> |
| 55 | + <p className="text-[13.5px] leading-snug text-zinc-100">{e.title}</p> |
| 56 | + {e.body && ( |
| 57 | + <button |
| 58 | + onClick={() => setOpen((o) => !o)} |
| 59 | + className="mt-0.5 flex shrink-0 items-center gap-0.5 text-[11px] text-zinc-500 transition hover:text-zinc-300" |
| 60 | + > |
| 61 | + {t('whatsnew.details')} |
| 62 | + <ChevronDown size={12} className={`transition ${open ? 'rotate-180' : ''}`} /> |
| 63 | + </button> |
| 64 | + )} |
| 65 | + </div> |
| 66 | + {open && e.body && ( |
| 67 | + <div className="md-prose mt-2 border-l border-white/10 pl-3 text-xs text-zinc-400"> |
| 68 | + <Markdown remarkPlugins={[remarkGfm]}>{e.body}</Markdown> |
| 69 | + </div> |
| 70 | + )} |
| 71 | + </div> |
| 72 | + </li> |
| 73 | + ); |
| 74 | +} |
| 75 | + |
27 | 76 | export function WhatsNew() { |
28 | 77 | const { user } = useAuth(); |
29 | 78 | const { t } = useT(); |
@@ -51,40 +100,43 @@ export function WhatsNew() { |
51 | 100 | } |
52 | 101 |
|
53 | 102 | if (!data?.show || typeof document === 'undefined') return null; |
| 103 | + const entries = data.entries ?? []; |
| 104 | + const extra = (data.count ?? entries.length) - entries.length; |
54 | 105 |
|
55 | 106 | return createPortal( |
56 | 107 | <div className="fixed inset-0 z-[120] flex items-center justify-center p-4"> |
57 | 108 | <div className="absolute inset-0 bg-black/60 backdrop-blur-sm" onClick={dismiss} /> |
58 | | - <div className="relative flex max-h-[85vh] w-full max-w-lg flex-col overflow-hidden rounded-2xl border border-white/10 bg-[#15151d] shadow-2xl"> |
59 | | - <div className="flex items-start justify-between gap-3 border-b border-white/[0.07] px-5 py-4"> |
60 | | - <div className="flex items-center gap-3"> |
61 | | - <span className="grid h-10 w-10 shrink-0 place-items-center rounded-xl bg-gradient-to-br from-violet-500/30 to-fuchsia-500/20 text-violet-200"> |
62 | | - <Sparkles size={20} /> |
63 | | - </span> |
64 | | - <div> |
65 | | - <h2 className="font-semibold text-white">{t('whatsnew.title')}</h2> |
66 | | - {data.version && ( |
67 | | - <p className="text-xs text-zinc-500"> |
68 | | - {t('whatsnew.version', { version: data.version })} |
69 | | - {typeof data.count === 'number' && data.count > 0 && ` · ${t('whatsnew.changes', { count: data.count })}`} |
70 | | - </p> |
71 | | - )} |
72 | | - </div> |
| 109 | + <div className="relative flex max-h-[85vh] w-full max-w-md flex-col overflow-hidden rounded-2xl border border-white/10 bg-[#15151d] shadow-2xl"> |
| 110 | + <div className="flex items-start justify-between gap-3 px-6 pt-5"> |
| 111 | + <div> |
| 112 | + <p className="text-[11px] font-semibold uppercase tracking-[0.16em] text-violet-300/90">{t('whatsnew.label')}</p> |
| 113 | + <h2 className="mt-1.5 text-xl font-semibold tracking-tight text-white">{t('whatsnew.title')}</h2> |
| 114 | + {data.version && ( |
| 115 | + <p className="mt-1 font-mono text-xs text-zinc-500"> |
| 116 | + {t('whatsnew.version', { version: data.version })} |
| 117 | + {typeof data.count === 'number' && data.count > 0 && ` · ${t('whatsnew.changes', { count: data.count })}`} |
| 118 | + </p> |
| 119 | + )} |
73 | 120 | </div> |
74 | 121 | <button |
75 | 122 | onClick={dismiss} |
76 | 123 | aria-label={t('whatsnew.dismiss')} |
77 | | - className="rounded-lg p-1.5 text-zinc-400 transition hover:bg-white/5 hover:text-zinc-100" |
| 124 | + className="-mr-1 rounded-lg p-1.5 text-zinc-500 transition hover:bg-white/5 hover:text-zinc-200" |
78 | 125 | > |
79 | 126 | <X size={18} /> |
80 | 127 | </button> |
81 | 128 | </div> |
82 | 129 |
|
83 | | - <div className="md-prose overflow-y-auto px-5 py-4 text-sm"> |
84 | | - <Markdown remarkPlugins={[remarkGfm]}>{data.notes ?? ''}</Markdown> |
85 | | - </div> |
| 130 | + <div className="mx-6 mt-4 border-t border-white/[0.07]" /> |
| 131 | + |
| 132 | + <ul className="space-y-3.5 overflow-y-auto px-6 py-4"> |
| 133 | + {entries.map((e, i) => ( |
| 134 | + <EntryRow key={i} e={e} /> |
| 135 | + ))} |
| 136 | + {extra > 0 && <li className="pl-9 text-xs italic text-zinc-500">{t('whatsnew.more', { count: extra })}</li>} |
| 137 | + </ul> |
86 | 138 |
|
87 | | - <div className="border-t border-white/[0.07] px-5 py-3 text-right"> |
| 139 | + <div className="border-t border-white/[0.07] px-6 py-3.5 text-right"> |
88 | 140 | <button className="btn-primary" onClick={dismiss}> |
89 | 141 | {t('whatsnew.gotIt')} |
90 | 142 | </button> |
|
0 commit comments