Showcase
Issue tracker
An issue tracker: projects in a sidebar, search on Ctrl/⌘ K, a filtered list with bulk actions, an issue panel with its fields and comments, and settings with a danger zone.
Source
Only the system's components and token utilities; the layout is Tailwind.
showcases/web-app/App.tsx
1
/* An issue tracker for the Northwind team: a sidebar with the inbox, the issue views and the2
* projects; a top bar with the breadcrumb, search (Ctrl/⌘ K) and the account menu; the issue list3
* with filters and bulk actions; an issue panel beside the list (or instead of it when the window is4
* narrow); project settings with a danger zone; toasts for what happened. All state lives here,5
* the views are in Issues.tsx, IssueDetail.tsx, Inbox.tsx, Settings.tsx and NewIssue.tsx.6
*7
* Keyboard: Ctrl/⌘ K searches issues and commands, C creates an issue. Both are bound on the8
* app's root, so they work while the app has focus and leave the page's own keys alone.9
* Below 720px the app shows one view at a time, picked at the bottom.10
*11
* A rounded app: the page that hosts it has <html data-shape="rounded"> (index.json tells the12
* docs site), so no button, toggle or switcher here names a shape, and its dialogs follow. */13
import { useMemo, useRef, useState, type KeyboardEvent, type MouseEvent } from "react";14
import { Bell, CheckCircle, Circle, Cube, Gear, ListChecks, MagnifyingGlass, Plus, SignOut, User, UserPlus } from "@phosphor-icons/react";15
import { Avatar, Breadcrumb, Button, CommandPalette, Kbd, LoadingState, Menu, Select, SegmentedControl, SidebarNav, Splitter, Toast, toast, type CommandPaletteItem, type MenuEntry } from "@fndn/react";16
import { ISSUES, ME, NOTIFICATIONS, PROJECTS, TODAY, personOf, statusOf, type Issue } from "./data";17
import { Inbox } from "./Inbox";18
import { IssueDetail, describe, type IssueChange } from "./IssueDetail";19
import { Issues, NO_FILTER, type Bulk } from "./Issues";20
import { NewIssue, type Draft } from "./NewIssue";21
import { Settings } from "./Settings";22
import { useWidth } from "./useWidth";23
24
/** inbox · my issues · all issues · one project's issues · that project's settings */25
type View = "inbox" | "mine" | "all" | "project" | "settings";26
const mod = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent) ? "⌘" : "Ctrl";27
const issues = (n: number) => (n === 1 ? "1 issue" : `${n} issues`);28
29
const ACCOUNT_MENU: MenuEntry[] = [30
{ type: "group", label: `${ME.label} · ${ME.email}`, items: [31
{ value: "mine", label: "My issues", icon: <User data-slot="icon" weight="bold" /> },32
{ value: "settings", label: "Project settings", icon: <Gear data-slot="icon" weight="bold" /> },33
{ value: "invite", label: "Invite teammates", icon: <UserPlus data-slot="icon" weight="bold" /> },34
] },35
{ type: "separator" },36
{ value: "sign-out", label: "Sign out", icon: <SignOut data-slot="icon" weight="bold" /> },37
];38
39
export default function App() {40
const [root, width] = useWidth();41
const phone = width > 0 && width < 720;42
/* the issue panel sits beside the list only when both have room (the list keeps its titles43
* readable); narrower, the issue takes the list's place at a reading width, as Linear's */44
const split = width >= 1100;45
46
const [all, setAll] = useState<Issue[]>(ISSUES);47
const [projects, setProjects] = useState(PROJECTS);48
const [inbox, setInbox] = useState(NOTIFICATIONS);49
const [note, setNote] = useState<string | null>(null);50
const [view, setView] = useState<View>("project");51
const [project, setProject] = useState("web-app");52
const [openId, setOpenId] = useState<string | null>(null);53
const [selected, setSelected] = useState<string[]>([]);54
const [filter, setFilter] = useState(NO_FILTER);55
const [loading, setLoading] = useState(false);56
const [collapsed, setCollapsed] = useState(false);57
const [palette, setPalette] = useState(false);58
const [creating, setCreating] = useState(false);59
const [sizes, setSizes] = useState([58, 42]);60
const timer = useRef<ReturnType<typeof setTimeout>>(undefined);61
62
const current = projects.find((p) => p.value === project) ?? projects[0];63
const open = all.find((i) => i.id === openId) ?? null;64
const scoped = useMemo(65
() => (view === "mine" ? all.filter((i) => i.assignee === ME.value) : view === "all" ? all : all.filter((i) => i.project === project)),66
[all, view, project],67
);68
69
/* ── navigation ─────────────────────────────────────────── */70
const go = (to: View, p = project) => {71
if (to !== view || p !== project) setFilter(NO_FILTER);72
/* wide, the inbox opens on the newest notification (Linear's), which is then read */73
if (to === "inbox" && view !== "inbox" && split && !note && inbox[0]) pickNote(inbox[0].id);74
setView(to);75
setSelected([]);76
if (to !== "project" || p !== project) setOpenId(null);77
/* another project's issues "load" for a moment; the views already on screen show at once */78
if (to === "project" && p !== project) {79
clearTimeout(timer.current);80
setLoading(true);81
timer.current = setTimeout(() => setLoading(false), 500);82
}83
setProject(p);84
};85
const openIssue = (id: string) => {86
const issue = all.find((i) => i.id === id);87
if (!issue) return;88
/* from the inbox or settings, or for another project's issue: that project's list */89
if (view === "inbox" || view === "settings" || (view === "project" && issue.project !== project)) go("project", issue.project);90
setOpenId(id);91
};92
93
/* ── changes ────────────────────────────────────────────── */94
const now = () => "just now";95
const event = (text: string) => ({ id: `e${Date.now()}${Math.random()}`, who: ME.value, when: now(), kind: "event" as const, text });96
const change = (id: string, patch: IssueChange) => {97
const text = describe(patch);98
setAll((list) => list.map((i) => (i.id === id ? { ...i, ...patch, activity: text ? [...i.activity, event(text)] : i.activity } : i)));99
};100
const comment = (id: string, body: string) =>101
setAll((list) => list.map((i) => (i.id === id ? { ...i, activity: [...i.activity, { id: `m${Date.now()}`, who: ME.value, when: now(), kind: "comment", body }] } : i)));102
103
const bulk = (ids: string[], what: Bulk) => {104
const before = all;105
if ("remove" in what) {106
setAll((list) => list.filter((i) => !ids.includes(i.id)));107
if (openId && ids.includes(openId)) setOpenId(null);108
toast({ title: `${issues(ids.length)} deleted`, action: { label: "Undo", onClick: () => setAll(before) } });109
return;110
}111
ids.forEach((id) => change(id, what));112
const to = "status" in what ? `moved to ${statusOf(what.status).label}` : what.assignee ? `assigned to ${what.assignee === ME.value ? "you" : personOf(what.assignee)?.label}` : "unassigned";113
toast({ title: `${issues(ids.length)} ${to}`, tone: "green", duration: 3000, action: { label: "Undo", onClick: () => setAll(before) } });114
};115
116
const create = (draft: Draft) => {117
const key = projects.find((p) => p.value === draft.project)?.key ?? "WEB";118
const next = Math.max(0, ...all.filter((i) => i.id.startsWith(`${key}-`)).map((i) => Number(i.id.split("-")[1]))) + 1;119
const id = `${key}-${next}`;120
setAll((list) => [{ ...draft, id, due: null, labels: [], activity: [{ id: `c${id}`, who: ME.value, when: now(), kind: "event", text: "created the issue" }] }, ...list]);121
setCreating(false);122
if (view === "project" && draft.project !== project) go("project", draft.project);123
setOpenId(id);124
toast({ title: `${id} created`, description: draft.title, tone: "green", duration: 4000 });125
};126
127
const removeProject = (archived: boolean) => {128
const gone = current!;129
const rest = projects.filter((p) => p.value !== gone.value);130
setProjects(rest);131
if (!archived) setAll((list) => list.filter((i) => i.project !== gone.value));132
go("all", rest[0]?.value ?? "");133
toast(archived134
? { title: `${gone.label} archived`, description: "Restore it from workspace settings.", action: { label: "Undo", onClick: () => setProjects(projects) } }135
: { title: `${gone.label} deleted`, tone: "red" });136
};137
138
/* ── commands: the palette and the shortcuts ─────────────── */139
/* the system's command palette (Linear's ⌘K): the first row starts highlighted, so Enter runs it;140
* rows are listed under their group, each with its icon; an issue shows its key as meta */141
const commands = useMemo((): CommandPaletteItem[] => [142
{ value: "new", label: "Create issue", group: "Actions", shortcut: ["C"], icon: <Plus data-slot="icon" weight="bold" /> },143
{ value: "go:inbox", label: "Go to inbox", group: "Navigation", icon: <Bell data-slot="icon" weight="bold" /> },144
{ value: "go:mine", label: "Go to my issues", group: "Navigation", icon: <User data-slot="icon" weight="bold" /> },145
{ value: "go:settings", label: "Open project settings", group: "Navigation", icon: <Gear data-slot="icon" weight="bold" /> },146
...projects.map((p) => ({ value: `project:${p.value}`, label: `Open ${p.label}`, group: "Projects", icon: <Cube data-slot="icon" weight="bold" /> })),147
...all.map((i) => ({148
value: `issue:${i.id}`, label: i.title, meta: i.id, group: "Issues", keywords: [i.id],149
icon: i.status === "done" ? <CheckCircle data-slot="icon" weight="bold" /> : <Circle data-slot="icon" weight="bold" />,150
})),151
], [all, projects]);152
const run = (value: string) => {153
if (value === "new") setCreating(true);154
else if (value.startsWith("go:")) go(value.slice(3) as View);155
else if (value.startsWith("project:")) go("project", value.slice(8));156
else if (value.startsWith("issue:")) openIssue(value.slice(6));157
};158
const account = (value: string) => {159
if (value === "mine" || value === "settings") go(value);160
else if (value === "invite") toast({ title: "Invite link copied", description: "Anyone with it can join Northwind as a member for 7 days.", duration: 4000 });161
else if (value === "sign-out") toast({ title: "Signing out is turned off in this demo" });162
};163
const typing = (el: Element) => el.closest("input, textarea, [contenteditable=true], [role=combobox], [role=dialog], [role=alertdialog]");164
const onKeyDown = (e: KeyboardEvent) => {165
if ((e.ctrlKey || e.metaKey) && !e.altKey && e.key.toLowerCase() === "k") { e.preventDefault(); e.stopPropagation(); setPalette(true); return; }166
if (e.key === "c" && !e.ctrlKey && !e.metaKey && !e.altKey && !typing(e.target as Element)) { e.preventDefault(); setCreating(true); }167
};168
/* the sidebar's links are the app's routes: onNavigate keeps the page where it is and the app169
* follows the link in its own state */170
const navigate = (value: string, _href: string, e: MouseEvent<HTMLAnchorElement>) => {171
e.preventDefault();172
if (projects.some((p) => p.value === value)) go("project", value); else go(value as View);173
};174
const unread = inbox.filter((n) => !n.read).length;175
176
/* ── the views ──────────────────────────────────────────── */177
const sidebarCurrent = view === "project" ? project : view;178
const sidebar = (179
<div className="flex h-full shrink-0 border-e border-line bg-surface pt-1">180
<SidebarNav181
size="sm" label="Northwind" logo={<ListChecks data-slot="icon" weight="bold" />}182
workspaces={[{ value: "northwind", label: "Northwind" }]} workspace="northwind"183
actions={[{ value: "invite", label: "Invite teammates", icon: "user-plus" }, { value: "settings", label: "Project settings", icon: "gear" }]}184
onWorkspaceAction={account}185
items={[186
{ value: "inbox", label: "Inbox", href: "#inbox", icon: "bell", badge: unread ? String(unread) : undefined },187
{ value: "mine", label: "My issues", href: "#mine", icon: <User data-slot="icon" weight="bold" /> },188
{ value: "all", label: "All issues", href: "#all", icon: <ListChecks data-slot="icon" weight="bold" /> },189
{ value: "settings", label: "Project settings", href: "#settings", icon: "gear" },190
]}191
sections={[{ value: "projects", label: "Projects", items: projects.map((p) => ({ value: p.value, label: p.label, href: `#${p.value}`, icon: "cube" })) }]}192
current={sidebarCurrent}193
onNavigate={navigate}194
collapsed={collapsed} onCollapsedChange={setCollapsed}195
/>196
</div>197
);198
199
const scopeName = view === "mine" ? "My issues" : view === "all" ? "All issues" : current?.label ?? "Northwind";200
const projectPicker = phone && view === "project" && (201
<Select size="sm" variant="ghost" className="font-semibold" aria-label="Project" items={projects} value={project} onValueChange={(v) => v && go("project", v)} />202
);203
const list = loading ? (204
<div className="grid h-full place-items-center"><LoadingState variant="dots" label={`Loading ${scopeName} issues`} /></div>205
) : (206
<Issues207
key={`${view}:${project}`} issues={scoped} scope={scopeName} filter={filter} onFilterChange={setFilter} openId={openId} onOpen={setOpenId}208
selected={selected} onSelectedChange={setSelected} onBulk={bulk} onNew={() => setCreating(true)} phone={phone} start={projectPicker}209
/>210
);211
const detail = open && (212
<IssueDetail213
issue={open} replaces={!split} onClose={() => setOpenId(null)}214
onChange={(patch) => change(open.id, patch)} onComment={(body) => comment(open.id, body)}215
/>216
);217
/* side by side, the splitter stays mounted (the list keeps its scroll); a closed panel has no size */218
const issueViews = !split ? (open ? detail : list) : (219
<Splitter220
className="h-full" handleLabel="Resize the issue panel" size={open ? sizes : [100, 0]}221
onSizeChange={(s) => { if (!open) return; if (s[1] === 0) setOpenId(null); else setSizes(s); }}222
panels={[{ id: "list", minSize: 40, content: list }, { id: "issue", minSize: 30, maxSize: 55, collapsible: true, content: detail || null }]}223
/>224
);225
/* the inbox: wide, the notification's issue beside the list; narrow, the issue in its project */226
const noteIssue = all.find((i) => i.id === inbox.find((n) => n.id === note)?.issue) ?? null;227
const pickNote = (id: string) => {228
const n = inbox.find((x) => x.id === id);229
if (!n) return;230
setInbox((list) => list.map((x) => (x.id === id ? { ...x, read: true } : x)));231
if (split) setNote(id); else openIssue(n.issue);232
};233
const main =234
view === "inbox" ? (235
<Inbox236
items={inbox} issues={all} current={note} onSelect={pickNote} split={split}237
onMarkAllRead={() => setInbox((list) => list.map((n) => ({ ...n, read: true })))}238
preview={noteIssue && (239
<IssueDetail240
issue={noteIssue} replaces={false} onClose={() => setNote(null)}241
onChange={(patch) => change(noteIssue.id, patch)} onComment={(body) => comment(noteIssue.id, body)}242
/>243
)}244
/>245
)246
: view === "settings" && current ? (247
<Settings248
key={current.value} project={current} issueCount={all.filter((i) => i.project === current.value).length}249
onRename={(label, key) => setProjects((ps) => ps.map((p) => (p.value === current.value ? { ...p, label, key } : p)))}250
onArchive={() => removeProject(true)} onDelete={() => removeProject(false)}251
/>252
) : issueViews;253
254
const crumbs = [255
{ label: "Northwind", href: "#all" },256
...(view === "project" || view === "settings" ? [{ label: current?.label ?? "", href: "#project" }] : []),257
{ label: view === "inbox" ? "Inbox" : view === "settings" ? "Settings" : view === "mine" ? "My issues" : view === "all" ? "All issues" : "Issues", href: open ? "#list" : undefined },258
...(open && view !== "inbox" && view !== "settings" ? [{ label: open.id }] : []),259
];260
const crumb = (href: string | undefined) => {261
if (href === "#all") go("all");262
else if (href === "#project") go("project");263
else if (href === "#list") setOpenId(null);264
};265
266
const header = (267
<header className="flex h-12 shrink-0 items-center gap-3 border-b border-line px-4 max-sm:gap-1.5 max-sm:ps-3 max-sm:pe-2">268
<Breadcrumb className="min-w-0 flex-1" label="You are here" items={crumbs} maxItems={phone ? 2 : undefined} onNavigate={crumb} />269
{phone ? (270
<>271
<Button variant="ghost" size="md" square muted aria-label="Search issues and commands" icon={<MagnifyingGlass data-slot="icon" weight="bold" />} onClick={() => setPalette(true)} />272
<Button variant="ghost" size="md" square muted aria-label="New issue" icon={<Plus data-slot="icon" weight="bold" />} onClick={() => setCreating(true)} />273
</>274
) : (275
<span className="relative flex w-64 max-w-[40%]">276
<Button variant="outline" size="sm" className="w-full justify-start pe-16 text-ink-3" icon={<MagnifyingGlass data-slot="icon" weight="bold" />} aria-keyshortcuts="Control+K Meta+K" onClick={() => setPalette(true)} data-app="search">277
Search issues278
</Button>279
<span className="pointer-events-none absolute inset-y-0 end-1.5 flex items-center" aria-hidden><Kbd keys={[mod, "K"]} /></span>280
</span>281
)}282
<Menu items={ACCOUNT_MENU} placement="bottom-end" onSelect={account}>283
<Button variant="ghost" size={phone ? "md" : "sm"} square aria-label={`Account: ${ME.label}`} icon={<Avatar name={ME.label} color={ME.color} size="20" />} data-app="account" />284
</Menu>285
</header>286
);287
288
const phoneNav = (289
<nav aria-label="Views" className="shrink-0 border-t border-line p-2">290
<SegmentedControl291
fill size="md" className="w-full" aria-label="View" value={view === "project" ? "issues" : view === "all" ? "issues" : view}292
onValueChange={(v) => go(v === "issues" ? "project" : (v as View))}293
options={[294
{ value: "inbox", label: "Inbox", count: unread || undefined },295
{ value: "issues", label: "Issues" },296
{ value: "mine", label: "Mine" },297
{ value: "settings", label: "Settings" },298
]}299
/>300
</nav>301
);302
303
return (304
<div305
ref={root} tabIndex={-1} onKeyDown={onKeyDown} data-showcase="web-app" data-layout={phone ? "phone" : split ? "split" : "single"} data-today={TODAY}306
className="flex h-full bg-page text-ink outline-none"307
>308
{!phone && sidebar}309
<div className="flex min-w-0 flex-1 flex-col">310
{header}311
<main className="min-h-0 flex-1">{main}</main>312
{phone && phoneNav}313
</div>314
315
<CommandPalette316
items={commands} limit={8} hotkey={false} open={palette} onOpenChange={setPalette} onSelect={run}317
title="Search" label="Search issues and commands" placeholder="Search issues, projects and commands…"318
emptyTitle="Nothing matches" emptyHint="Try an issue number such as WEB-482, or a word from its title."319
/>320
<NewIssue open={creating} onOpenChange={setCreating} project={view === "project" ? project : "web-app"} onCreate={create} />321
<Toast />322
</div>323
);324
}1
/* The tracker's data: the Northwind workspace, its people and projects, the issues with their2
* activity, and the inbox. "Today" is fixed so the dates read the same on every visit. */3
4
export const TODAY = "2026-11-18";5
6
export type Person = { value: string; label: string; email: string; color: string };7
export const PEOPLE: Person[] = [8
{ value: "maya", label: "Maya Chen", email: "maya@northwind.example", color: "oklch(0.55 0.15 255)" },9
{ value: "daniel", label: "Daniel Okafor", email: "daniel@northwind.example", color: "oklch(0.55 0.13 150)" },10
{ value: "priya", label: "Priya Raman", email: "priya@northwind.example", color: "oklch(0.6 0.15 45)" },11
{ value: "lucas", label: "Lucas Moreau", email: "lucas@northwind.example", color: "oklch(0.55 0.15 310)" },12
{ value: "aiko", label: "Aiko Tanaka", email: "aiko@northwind.example", color: "oklch(0.58 0.14 200)" },13
{ value: "sofia", label: "Sofia Alvarez", email: "sofia@northwind.example", color: "oklch(0.58 0.16 20)" },14
{ value: "jonas", label: "Jonas Weber", email: "jonas@northwind.example", color: "oklch(0.5 0.03 260)" },15
];16
export const ME = PEOPLE[0]!;17
export const personOf = (value: string | null) => PEOPLE.find((p) => p.value === value);18
19
export type Project = { value: string; label: string; key: string };20
export const PROJECTS: Project[] = [21
{ value: "web-app", label: "web-app", key: "WEB" },22
{ value: "billing-api", label: "billing-api", key: "BIL" },23
{ value: "mobile", label: "mobile", key: "MOB" },24
{ value: "docs-site", label: "docs-site", key: "DOC" },25
{ value: "data-pipeline", label: "data-pipeline", key: "DAT" },26
];27
28
/** In the order a board would show them; `tone` is the StatusPill's. */29
export const STATUSES = [30
{ value: "backlog", label: "Backlog", tone: "neutral" },31
{ value: "todo", label: "Todo", tone: "neutral" },32
{ value: "progress", label: "In progress", tone: "blue" },33
{ value: "review", label: "In review", tone: "orange" },34
{ value: "done", label: "Done", tone: "green" },35
] as const;36
export type Status = (typeof STATUSES)[number]["value"];37
export const statusOf = (value: Status) => STATUSES.find((s) => s.value === value)!;38
39
export const PRIORITIES = [40
{ value: "urgent", label: "Urgent" },41
{ value: "high", label: "High" },42
{ value: "medium", label: "Medium" },43
{ value: "low", label: "Low" },44
{ value: "none", label: "No priority" },45
] as const;46
export type Priority = (typeof PRIORITIES)[number]["value"];47
export const priorityOf = (value: Priority) => PRIORITIES.find((p) => p.value === value)!;48
49
/** Each label keeps one Tag hue everywhere. */50
export const LABEL_TONES: Record<string, "red" | "blue" | "purple" | "green" | "orange" | "cyan" | "pink" | "yellow"> = {51
bug: "red", feature: "blue", performance: "orange", billing: "green", design: "purple", infra: "cyan", docs: "yellow", "good first issue": "pink",52
};53
export const toneOf = (label: string) => LABEL_TONES[label] ?? "neutral";54
55
export type Activity = { id: string; who: string; when: string } & ({ kind: "event"; text: string } | { kind: "comment"; body: string });56
57
export type Issue = {58
id: string;59
project: string;60
title: string;61
status: Status;62
priority: Priority;63
assignee: string | null;64
/** ISO date, or null. */65
due: string | null;66
labels: string[];67
description: string;68
activity: Activity[];69
};70
71
const created = (who: string, when: string): Activity => ({ id: `c-${when}-${who}`, who, when, kind: "event", text: "created the issue" });72
73
export const ISSUES: Issue[] = [74
{75
id: "WEB-482", project: "web-app", title: "Add retry to webhook delivery", status: "review", priority: "high", assignee: "maya", due: "2026-11-20",76
labels: ["feature", "infra"],77
description: "Deliveries that time out are dropped today. Retry three times with exponential backoff (1 s, 4 s, 16 s), then mark the endpoint as failing and email the workspace owner.",78
activity: [79
created("daniel", "Nov 11"),80
{ id: "a1", who: "daniel", when: "Nov 11", kind: "event", text: "set priority to High" },81
{ id: "a2", who: "maya", when: "Nov 14", kind: "event", text: "moved this to In review" },82
{ id: "a3", who: "priya", when: "Nov 15", kind: "comment", body: "Backoff looks right. Can we log each attempt in the delivery log so support can see why an event arrived late?" },83
{ id: "a4", who: "maya", when: "Nov 15", kind: "comment", body: "Good call, added in a1b2c3d. Each attempt now shows its status code and duration." },84
],85
},86
{87
id: "WEB-479", project: "web-app", title: "Usage alerts fire twice for one project", status: "progress", priority: "urgent", assignee: "lucas", due: "2026-11-17",88
labels: ["bug"],89
description: "Customers on the Team plan get two emails when a project crosses 80% of its quota. The alert job runs on both workers since the queue migration.",90
activity: [created("sofia", "Nov 16"), { id: "b1", who: "lucas", when: "Nov 17", kind: "event", text: "moved this to In progress" }],91
},92
{93
id: "WEB-476", project: "web-app", title: "Dark mode: chart tooltips are unreadable on the usage page", status: "todo", priority: "medium", assignee: "aiko", due: "2026-11-27",94
labels: ["bug", "design"],95
description: "Tooltip text uses the light-theme ink on the dark tooltip background.",96
activity: [created("aiko", "Nov 13")],97
},98
{99
id: "WEB-471", project: "web-app", title: "Invite teammates from the project page", status: "todo", priority: "medium", assignee: "priya", due: null,100
labels: ["feature"],101
description: "Owners ask for an invite button next to the member list instead of going through workspace settings.",102
activity: [created("maya", "Nov 9")],103
},104
{105
id: "WEB-468", project: "web-app", title: "Deploy logs page loads every line at once and freezes on long builds", status: "backlog", priority: "high", assignee: null, due: null,106
labels: ["performance"],107
description: "A 40,000-line build log blocks the main thread for several seconds. Stream it and virtualise the list.",108
activity: [created("jonas", "Nov 2")],109
},110
{111
id: "WEB-463", project: "web-app", title: "Keyboard shortcut to switch environments", status: "backlog", priority: "low", assignee: null, due: null,112
labels: ["feature", "good first issue"],113
description: "Alt+1/2/3 for Production, Staging and Preview on the deploys page.",114
activity: [created("lucas", "Oct 29")],115
},116
{117
id: "WEB-455", project: "web-app", title: "Session expires while a long form is open", status: "done", priority: "high", assignee: "daniel", due: "2026-11-12",118
labels: ["bug"],119
description: "Refresh the session in the background while the tab is visible.",120
activity: [created("sofia", "Oct 24"), { id: "c1", who: "daniel", when: "Nov 12", kind: "event", text: "moved this to Done" }],121
},122
{123
id: "BIL-212", project: "billing-api", title: "Invoice INV-2024-0117 shows the wrong VAT rate for Ireland", status: "progress", priority: "urgent", assignee: "maya", due: "2026-11-18",124
labels: ["bug", "billing"],125
description: "Irish customers were charged 21% instead of 23% after the tax table update.",126
activity: [created("sofia", "Nov 17"), { id: "d1", who: "maya", when: "Nov 17", kind: "event", text: "moved this to In progress" }],127
},128
{129
id: "BIL-209", project: "billing-api", title: "Prorate seat changes in the middle of a billing cycle", status: "todo", priority: "high", assignee: "daniel", due: "2026-12-01",130
labels: ["billing", "feature"],131
description: "Adding a seat on day 12 should charge 18/30 of the seat price, not the full month.",132
activity: [created("maya", "Nov 6")],133
},134
{135
id: "BIL-204", project: "billing-api", title: "Card declined emails go to the workspace owner only", status: "backlog", priority: "medium", assignee: null, due: null,136
labels: ["billing"],137
description: "Billing contacts set in settings never receive them.",138
activity: [created("priya", "Oct 30")],139
},140
{141
id: "MOB-88", project: "mobile", title: "Push notification opens the wrong project", status: "review", priority: "high", assignee: "aiko", due: "2026-11-21",142
labels: ["bug"],143
description: "Tapping a deploy notification for billing-api opens web-app when the app was in the background.",144
activity: [created("aiko", "Nov 12")],145
},146
{147
id: "MOB-85", project: "mobile", title: "Offline banner covers the tab bar on small phones", status: "todo", priority: "low", assignee: "jonas", due: null,148
labels: ["design"],149
description: "",150
activity: [created("jonas", "Nov 8")],151
},152
{153
id: "DOC-61", project: "docs-site", title: "Document preview deploys for pull requests", status: "progress", priority: "medium", assignee: "priya", due: "2026-11-25",154
labels: ["docs"],155
description: "Cover the GitHub check, the comment with the preview URL, and how to protect previews with a password.",156
activity: [created("priya", "Nov 10")],157
},158
{159
id: "DAT-140", project: "data-pipeline", title: "Nightly export to the warehouse skips rows with emoji in the name", status: "todo", priority: "high", assignee: "jonas", due: "2026-11-22",160
labels: ["bug", "infra"],161
description: "The CSV writer uses latin-1. Switch to UTF-8 and backfill the last 14 days.",162
activity: [created("daniel", "Nov 15")],163
},164
];165
166
export type Notification = { id: string; who: string; issue: string; text: string; when: string; read: boolean };167
export const NOTIFICATIONS: Notification[] = [168
{ id: "n1", who: "priya", issue: "WEB-482", text: "commented: Backoff looks right. Can we log each attempt…", when: "2 h ago", read: false },169
{ id: "n2", who: "sofia", issue: "BIL-212", text: "assigned you", when: "Yesterday", read: false },170
{ id: "n3", who: "lucas", issue: "WEB-479", text: "mentioned you: @maya the alert job runs on both workers", when: "Yesterday", read: true },171
];172
173
/** "Nov 20", for an ISO date. */174
export const shortDate = (iso: string) => new Date(`${iso}T12:00:00Z`).toLocaleDateString("en-US", { month: "short", day: "numeric", timeZone: "UTC" });175
export const overdue = (issue: Issue) => !!issue.due && issue.status !== "done" && issue.due < TODAY;1
/* The inbox: what happened to Maya's issues, newest first, unread ones marked with a dot. Wide,2
* it is Linear's list + preview: a notification opens its issue beside the list (and is read),3
* and the inbox opens on the newest one, so the preview is never a half-screen empty state;4
* narrow, a notification opens the issue in its project. "Mark all as read" clears the dots. */5
import type { ReactNode } from "react";6
import { Button, EmptyState, PageHeader, ScrollArea } from "@fndn/react";7
import { personOf, type Issue, type Notification } from "./data";8
import { AssigneeMark } from "./Issues";9
10
type Props = {11
items: Notification[];12
issues: Issue[];13
/** The notification shown in the preview (wide only). */14
current: string | null;15
onSelect: (id: string) => void;16
onMarkAllRead: () => void;17
/** Wide: the list and the preview side by side. Narrow: the list alone (a notification opens its issue in its project). */18
split: boolean;19
/** The issue beside the list (split only). */20
preview?: ReactNode;21
};22
23
export function Inbox({ items, issues, current, onSelect, onMarkAllRead, split, preview }: Props) {24
const unread = items.filter((n) => !n.read).length;25
const list = (26
<div className="flex h-full min-h-0 flex-col" data-app="inbox">27
{/* the ghost button's own padding brings its label to the pane's 16px: 8px at the end */}28
<PageHeader29
size="pane" className="shrink-0 pe-2" title="Inbox"30
description={unread > 0 ? `${unread} unread` : undefined}31
actions={unread > 0 && <Button variant="ghost" size="sm" muted onClick={onMarkAllRead}>Mark all as read</Button>}32
/>33
{items.length ? (34
<ScrollArea className="min-h-0 flex-1" aria-label="Notifications">35
<ul className="flex flex-col">36
{items.map((n) => {37
const who = personOf(n.who)!;38
const issue = issues.find((i) => i.id === n.issue);39
const on = split && n.id === current;40
return (41
<li key={n.id} className="border-b border-line-soft" data-notification={n.id} data-unread={n.read ? undefined : ""}>42
<button43
type="button" disabled={!issue} aria-current={on || undefined} onClick={() => onSelect(n.id)}44
className={`flex w-full items-start gap-2.5 py-2.5 ps-2 pe-4 text-start motion-colors-fast hover:bg-hover disabled:opacity-60 ${on ? "bg-hover" : ""}`}45
>46
{/* the unread dot keeps its column when read, so the rows share one text edge */}47
<span className="flex h-5 w-2 shrink-0 items-center justify-center" aria-hidden>48
{!n.read && <span className="size-1.5 rounded-full bg-accent" />}49
</span>50
<AssigneeMark id={n.who} size="20" />51
<span className="flex min-w-0 flex-1 flex-col gap-0.5">52
<span className="flex items-baseline gap-2">53
<span className="shrink-0 font-mono text-xs text-ink-2">{n.issue}</span>54
<span className={`truncate text-sm [unicode-bidi:plaintext] ${n.read ? "text-ink-2" : "font-medium text-ink"}`} title={issue?.title}>{issue?.title ?? "(deleted)"}</span>55
</span>56
<span className="truncate text-sm text-ink-2 [unicode-bidi:plaintext]" title={`${who.label} ${n.text}`}>57
<span className="text-ink-2">{who.label}</span> {n.text}58
</span>59
</span>60
<span className="shrink-0 text-xs leading-5 text-ink-2">{n.when}</span>61
{!n.read && <span className="sr-only">Unread</span>}62
</button>63
</li>64
);65
})}66
</ul>67
</ScrollArea>68
) : (69
<EmptyState className="flex-1" size="block" icon="chats" title="Nothing in your inbox" hint="Mentions, assignments and comments on your issues show up here." />70
)}71
</div>72
);73
if (!split) return list;74
return (75
<div className="grid h-full grid-cols-[minmax(18rem,26rem)_minmax(0,1fr)]">76
<div className="min-h-0 min-w-0 border-e border-line">{list}</div>77
<div className="min-h-0 min-w-0">78
{preview ?? <EmptyState className="h-full" size="block" icon="bell" title="No notification selected" hint="Pick one to read its issue here." />}79
</div>80
</div>81
);82
}1
/* One issue: its title and description (plain text, edited in place: the field shows only while2
* editing), the properties as ghost controls (Linear's: a value that reads as text and opens on a3
* click, its name in ink-2 beside it), then the activity with the comments and a composer at the4
* end. Every change goes up to the app, which records it in the activity. */5
import { useState } from "react";6
import { ArrowLeft, Link, X } from "@phosphor-icons/react";7
import {8
Avatar, Button, Card, CardBody, Combobox, DatePicker, Editable, Kbd, ScrollArea, Select, TagsInput, Textarea, Tooltip, toast,9
} from "@fndn/react";10
import { AssigneeMark } from "./Issues";11
import { LABEL_TONES, ME, PEOPLE, PRIORITIES, STATUSES, personOf, priorityOf, statusOf, type Activity, type Issue, type Priority, type Status } from "./data";12
13
export type IssueChange = Partial<Pick<Issue, "title" | "status" | "priority" | "assignee" | "due" | "labels" | "description">>;14
15
const ASSIGNEES = [{ value: "unassigned", label: "Unassigned" }, ...PEOPLE.map((p) => ({ value: p.value, label: p.label, meta: p.value === ME.value ? "You" : undefined }))];16
const mod = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent) ? "⌘" : "Ctrl";17
18
/** What a change says in the activity: "moved this to In review". */19
export function describe(change: IssueChange): string | null {20
if (change.status) return `moved this to ${statusOf(change.status).label}`;21
if (change.priority) return `set priority to ${priorityOf(change.priority).label}`;22
if ("assignee" in change) return change.assignee ? `assigned ${personOf(change.assignee)?.label}` : "removed the assignee";23
if ("due" in change) return change.due ? "changed the due date" : "removed the due date";24
if (change.title) return "renamed the issue";25
return null;26
}27
28
type Props = {29
issue: Issue;30
onChange: (change: IssueChange) => void;31
onComment: (body: string) => void;32
onClose: () => void;33
/** The panel replaces the list (phone, narrow window): its close button reads "Back". */34
replaces: boolean;35
};36
37
export function IssueDetail({ issue, onChange, onComment, onClose, replaces }: Props) {38
const [comment, setComment] = useState("");39
const send = () => { if (!comment.trim()) return; onComment(comment.trim()); setComment(""); };40
41
/* one row of the inspector: a name, then the control that changes it */42
const prop = (name: string, control: React.ReactNode) => (43
<>44
<dt className="flex h-7 items-center text-sm text-ink-2">{name}</dt>45
<dd className="min-w-0">{control}</dd>46
</>47
);48
49
return (50
<section className="flex h-full min-w-0 flex-col bg-surface" aria-label={`${issue.id} ${issue.title}`} data-app="detail">51
<header className="flex h-11 shrink-0 items-center gap-1 border-b border-line ps-2 pe-2">52
{replaces ? (53
<Button variant="ghost" size="sm" icon={<ArrowLeft data-slot="icon" weight="bold" />} onClick={onClose}>Issues</Button>54
) : (55
<Tooltip content="Close">56
<Button variant="ghost" size="sm" square muted aria-label="Close issue" icon={<X data-slot="icon" weight="bold" />} onClick={onClose} />57
</Tooltip>58
)}59
<span className="ms-1 font-mono text-xs text-ink-2">{issue.id}</span>60
<Tooltip content="Copy link">61
<Button62
variant="ghost" size="sm" square muted className="ms-auto" aria-label="Copy link to issue" icon={<Link data-slot="icon" weight="bold" />}63
onClick={() => toast({ title: "Link copied", description: `northwind.example/issues/${issue.id}`, duration: 3000 })}64
/>65
</Tooltip>66
</header>67
68
<ScrollArea className="min-h-0 flex-1">69
{/* in place of the list the issue keeps a reading width, as Linear's full issue view */}70
<div className={`flex flex-col gap-5 px-5 py-4 max-sm:px-4 ${replaces ? "mx-auto w-full max-w-[760px]" : ""}`}>71
{/* the key resets the field when another issue opens */}72
<Editable73
key={issue.id} variant="inline" aria-label="Title" activationMode="click" defaultValue={issue.title}74
className="text-lg font-semibold"75
onValueCommit={(title) => title.trim() && title !== issue.title && onChange({ title: title.trim() })}76
/>77
78
{/* the key resets the text when another issue opens */}79
<Editable80
key={`d:${issue.id}`} multiline size="sm" aria-label="Description" placeholder="Add a description…" defaultValue={issue.description}81
className="-mx-2"82
onValueCommit={(description) => description !== issue.description && onChange({ description })}83
/>84
85
<dl className="grid grid-cols-[6rem_minmax(0,1fr)] items-start gap-x-2 gap-y-0.5">86
{prop("Status", <Select size="sm" variant="ghost" className="w-full" aria-label="Status" items={STATUSES.map((s) => ({ value: s.value, label: s.label }))} value={issue.status} onValueChange={(v) => v && onChange({ status: v as Status })} />)}87
{prop("Priority", <Select size="sm" variant="ghost" className="w-full" aria-label="Priority" items={PRIORITIES.map((p) => ({ value: p.value, label: p.label }))} value={issue.priority} onValueChange={(v) => v && onChange({ priority: v as Priority })} />)}88
{prop("Assignee", (89
<Combobox90
size="sm" variant="ghost" className="w-full" aria-label="Assignee" placeholder="Unassigned" emptyText="No one in Northwind matches"91
caret={false} start={<AssigneeMark id={issue.assignee} size="20" />}92
items={ASSIGNEES} value={issue.assignee ?? "unassigned"} onValueChange={(v) => v && onChange({ assignee: v === "unassigned" ? null : v })}93
/>94
))}95
{prop("Due date", (96
<DatePicker97
size="sm" variant="ghost" className="w-full" aria-label="Due date" placeholder="No due date"98
value={issue.due ? [issue.due] : []} onValueChange={(v) => onChange({ due: v[0] ?? null })}99
/>100
))}101
{prop("Labels", <TagsInput size="sm" variant="ghost" tagVariant="outline" className="w-full" aria-label="Labels" placeholder="Add a label" tones={LABEL_TONES} value={issue.labels} onValueChange={(labels) => onChange({ labels })} />)}102
</dl>103
104
<section aria-labelledby="activity-title" className="flex flex-col gap-3">105
<h3 id="activity-title" className="text-sm font-semibold text-ink">Activity</h3>106
<ol className="flex flex-col gap-3">107
{issue.activity.map((a) => <Entry key={a.id} entry={a} />)}108
</ol>109
<div className="flex flex-col gap-2">110
<Textarea111
aria-label={`Comment on ${issue.id}`} placeholder="Leave a comment…" value={comment}112
onChange={(e) => setComment(e.target.value)}113
onKeyDown={(e) => { if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) { e.preventDefault(); send(); } }}114
/>115
<div className="flex items-center justify-end gap-2">116
<span className="text-xs text-ink-2 max-sm:hidden"><Kbd keys={[mod, "Enter"]} /> to send</span>117
<Button size="sm" variant="primary" disabled={!comment.trim()} onClick={send}>Comment</Button>118
</div>119
</div>120
</section>121
</div>122
</ScrollArea>123
</section>124
);125
}126
127
/** An event is one line; a comment is a card with its author. */128
function Entry({ entry }: { entry: Activity }) {129
const who = personOf(entry.who)!;130
if (entry.kind === "event") {131
return (132
<li className="flex items-start gap-2 text-sm text-ink-2">133
<Avatar name={who.label} color={who.color} size="16" className="mt-0.5 shrink-0" />134
<span className="[unicode-bidi:plaintext]"><span className="font-medium text-ink">{who.label}</span> {entry.text} <span className="text-ink-2">· {entry.when}</span></span>135
</li>136
);137
}138
return (139
<li>140
<Card elevation="hairline">141
<CardBody className="flex flex-col gap-1.5">142
<span className="flex items-center gap-2 text-sm">143
<Avatar name={who.label} color={who.color} size="16" />144
<span className="font-medium text-ink">{who.label}</span>145
<span className="text-ink-2">{entry.when}</span>146
</span>147
<p className="text-sm leading-relaxed whitespace-pre-wrap text-ink-2 [unicode-bidi:plaintext]">{entry.body}</p>148
</CardBody>149
</Card>150
</li>151
);152
}1
/* The issue list: status segments and an assignee filter over the issues; a row opens the issue,2
* its checkbox selects it, and a bulk bar (status, assignee, delete) opens under the toolbar while3
* rows are selected. Filters live here; the issues and the selection belong to the app.4
*5
* Desktop: Linear's and GitHub's list, a flush table of one-line rows (priority · ID · title ·6
* labels · status · assignee · due), no card, a hairline between rows; the title is the column that7
* gives way. The checkbox shows on a row's hover or focus, and on every row once one is picked.8
* Columns leave by the list's own width (container queries, so nothing is measured in script and9
* nothing reflows after the first paint): labels, then due, then assignee.10
* Phone: list rows (ID, status and assignee over the title); "Select" turns on the checkboxes. */11
import { useState, type ReactNode } from "react";12
import { DotsThree, Trash, User, Warning } from "@phosphor-icons/react";13
import {14
AlertDialog, Avatar, Button, Checkbox, EmptyState, Link, Menu, ScrollArea, SegmentedControl, Select, StatusPill, Table, TableBody, TableCell,15
TableHead, TableHeader, TableRow, Tag, Tooltip, type MenuEntry,16
} from "@fndn/react";17
import { ME, PEOPLE, STATUSES, overdue, personOf, priorityOf, shortDate, statusOf, toneOf, type Issue, type Priority, type Status } from "./data";18
19
export type Filter = { segment: string; assignee: string };20
/** Linear's default view: the work that is open. */21
export const NO_FILTER: Filter = { segment: "active", assignee: "anyone" };22
23
export type Bulk = { status: Status } | { assignee: string | null } | { remove: true };24
25
const SEGMENTS: Record<string, (i: Issue) => boolean> = {26
active: (i) => i.status === "todo" || i.status === "progress" || i.status === "review",27
backlog: (i) => i.status === "backlog",28
done: (i) => i.status === "done",29
all: () => true,30
};31
const ANYONE = NO_FILTER.assignee;32
const ASSIGNEES = [33
{ value: ANYONE, label: "Anyone" },34
{ value: "unassigned", label: "Unassigned" },35
...PEOPLE.map((p) => ({ value: p.value, label: p.value === ME.value ? `${p.label} (you)` : p.label })),36
];37
const STATUS_MENU: MenuEntry[] = STATUSES.map((s) => ({ value: s.value, label: s.label }));38
const ASSIGN_MENU: MenuEntry[] = [{ value: "unassigned", label: "Unassigned" }, { type: "separator" }, ...PEOPLE.map((p) => ({ value: p.value, label: p.label }))];39
40
const issues = (n: number) => (n === 1 ? "1 issue" : `${n} issues`);41
42
type Props = {43
issues: Issue[];44
/** What the list shows, for its name: "web-app", "All issues", "My issues". */45
scope: string;46
/** Kept by the app, so it survives the panel opening beside or instead of the list. */47
filter: Filter;48
onFilterChange: (filter: Filter) => void;49
openId: string | null;50
onOpen: (id: string) => void;51
selected: string[];52
onSelectedChange: (ids: string[]) => void;53
onBulk: (ids: string[], change: Bulk) => void;54
onNew: () => void;55
/** A phone: list rows instead of the table. */56
phone?: boolean;57
/** A control at the start of the toolbar (the project picker on a phone). */58
start?: ReactNode;59
};60
61
export function Issues({ issues: all, scope, filter: { segment, assignee }, onFilterChange, openId, onOpen, selected, onSelectedChange, onBulk, onNew, phone = false, start }: Props) {62
const setSegment = (v: string) => onFilterChange({ segment: v, assignee });63
const setAssignee = (v: string) => onFilterChange({ segment, assignee: v });64
const [confirm, setConfirm] = useState(false);65
/* a phone shows the checkboxes only in select mode (there is no hover to reveal them) */66
const [selecting, setSelecting] = useState(false);67
68
const byAssignee = (i: Issue) => assignee === ANYONE || (assignee === "unassigned" ? i.assignee === null : i.assignee === assignee);69
const shown = all.filter((i) => byAssignee(i) && SEGMENTS[segment]!(i));70
const count = (key: string) => all.filter((i) => byAssignee(i) && SEGMENTS[key]!(i)).length;71
72
/* only rows on screen stay selected: a filter that hides a row drops it from the bulk action */73
const picked = selected.filter((id) => shown.some((i) => i.id === id));74
const allPicked = shown.length > 0 && picked.length === shown.length ? true : picked.length ? "indeterminate" : false;75
const toggle = (id: string, on: boolean) => onSelectedChange(on ? [...picked, id] : picked.filter((x) => x !== id));76
const bulk = (change: Bulk) => { onBulk(picked, change); onSelectedChange([]); setSelecting(false); };77
const clearFilters = () => onFilterChange({ segment: "all", assignee: ANYONE });78
const stopSelecting = () => { onSelectedChange([]); setSelecting(false); };79
80
const segments = (81
<SegmentedControl82
size="sm" fill={phone} aria-label="Filter by status" value={segment} onValueChange={setSegment}83
options={[84
{ value: "active", label: "Active", count: count("active") },85
{ value: "backlog", label: "Backlog", count: count("backlog") },86
{ value: "done", label: "Done", count: count("done") },87
{ value: "all", label: "All", count: count("all") },88
]}89
/>90
);91
const assigneeFilter = (92
<Select size="sm" variant="ghost" aria-label="Assignee" items={ASSIGNEES} value={assignee} onValueChange={(v) => setAssignee(v ?? ANYONE)} />93
);94
95
return (96
<div className="@container flex h-full min-h-0 flex-col" data-app="issues">97
{phone ? (98
<div className="flex flex-col gap-2 px-3 pt-2 pb-2">99
<div className="flex items-center gap-1">100
{start}101
<span className="ms-auto" />102
{assigneeFilter}103
<Button variant="ghost" size="sm" onClick={() => (selecting ? stopSelecting() : setSelecting(true))} aria-pressed={selecting}>104
{selecting ? "Done" : "Select"}105
</Button>106
</div>107
{segments}108
</div>109
) : (110
<div className="flex flex-wrap items-center gap-2 px-4 pt-3 pb-2">111
{start}112
{segments}113
{assigneeFilter}114
{/* chrome, not content: the primary fill is kept for the dialog's "Create issue" */}115
<Button variant="outline" size="sm" className="ms-auto" aria-keyshortcuts="C" onClick={onNew}>116
New issue117
</Button>118
</div>119
)}120
121
{/* the bulk bar opens its row while rows are selected (instant from the keyboard) */}122
<div className={`grid kbd-instant motion-size-reveal ${picked.length ? "grid-rows-[1fr]" : "grid-rows-[0fr]"}`} inert={!picked.length}>123
<div className="min-h-0 overflow-hidden">124
<div className={`flex flex-wrap items-center gap-1 px-4 pb-2 kbd-instant motion-opacity-base max-sm:px-3 ${picked.length ? "opacity-100" : "opacity-0"}`} role="toolbar" aria-label="Selected issues" data-app="bulk">125
<span className="me-1 text-sm font-medium text-ink tabular-nums" role="status">{`${picked.length} selected`}</span>126
<Menu items={STATUS_MENU} triggerLabel="Status" onSelect={(v) => bulk({ status: v as Status })} />127
<Menu items={ASSIGN_MENU} triggerLabel="Assignee" onSelect={(v) => bulk({ assignee: v === "unassigned" ? null : v })} />128
{/* a phone has no room for four labels on one line: Delete, whose trash icon reads on its129
* own and whose dialog names what goes, becomes an icon at the far end, away from the130
* two menus that only move issues (Mail's and Linear's selection bars); the menus keep131
* their names */}132
{phone ? (133
<Tooltip content="Delete">134
<Button variant="ghost" size="sm" square className="ms-auto" aria-label="Delete" icon={<Trash data-slot="icon" weight="bold" />} onClick={() => setConfirm(true)} />135
</Tooltip>136
) : (137
<Button variant="ghost" size="sm" icon={<Trash data-slot="icon" weight="bold" />} onClick={() => setConfirm(true)}>Delete</Button>138
)}139
{!phone &&<Button variant="ghost" size="sm" muted className="ms-auto" onClick={() => onSelectedChange([])}>Clear selection</Button>}140
</div>141
</div>142
</div>143
144
<ScrollArea className="min-h-0 flex-1" aria-label={`Issues in ${scope}`}>145
{shown.length ? (146
phone ? (147
<ul className="flex flex-col border-t border-line-soft" aria-label={`Issues in ${scope}`}>148
{shown.map((issue) => (149
<PhoneRow key={issue.id} issue={issue} selecting={selecting} picked={picked.includes(issue.id)} onOpen={onOpen} onPick={toggle} />150
))}151
</ul>152
) : (153
<Table variant="flush" aria-label={`Issues in ${scope}`} data-picking={picked.length ? "" : undefined} className="group/list">154
<TableHeader>155
<TableRow>156
<TableHead className="w-0 pe-0 ps-4">157
<Checkbox aria-label="Select all issues" checked={allPicked} onCheckedChange={(on) => onSelectedChange(on === true ? shown.map((i) => i.id) : [])} />158
</TableHead>159
<TableHead className="w-0 px-2"><span className="sr-only">Priority</span></TableHead>160
<TableHead className="w-0 ps-0">ID</TableHead>161
<TableHead truncate>Title</TableHead>162
<TableHead className="hidden w-0 @4xl:table-cell"><span className="sr-only">Labels</span></TableHead>163
<TableHead className="w-0">Status</TableHead>164
<TableHead className="hidden w-0 pe-4 @xl:table-cell @2xl:pe-3"><span className="sr-only">Assignee</span></TableHead>165
<TableHead numeric className="hidden w-0 pe-4 @2xl:table-cell">Due</TableHead>166
</TableRow>167
</TableHeader>168
<TableBody>169
{shown.map((issue) => <Row key={issue.id} issue={issue} open={issue.id === openId} picked={picked.includes(issue.id)} onOpen={onOpen} onPick={toggle} />)}170
</TableBody>171
</Table>172
)173
) : all.length ? (174
<div className="flex flex-col items-center gap-3 px-4 py-12">175
<EmptyState size="block" icon="funnel" title="No issues match these filters" hint={`${issues(all.length)} in ${scope} are hidden by the status or assignee filter.`} />176
<Button size="sm" onClick={clearFilters}>Clear filters</Button>177
</div>178
) : (179
<div className="flex flex-col items-center gap-3 px-4 py-12">180
<EmptyState size="block" icon="folder-open" title={`No issues in ${scope} yet`} hint="Issues you create here show up in this list." />181
<Button size="sm" variant="primary" onClick={onNew}>New issue</Button>182
</div>183
)}184
</ScrollArea>185
186
<AlertDialog187
open={confirm} onOpenChange={setConfirm} tone="danger"188
title={`Delete ${issues(picked.length)}?`}189
description="They are removed for everyone in Northwind, with their comments and activity."190
actionLabel={`Delete ${issues(picked.length)}`}191
onAction={() => bulk({ remove: true })}192
/>193
</div>194
);195
}196
197
/** Linear's priority mark: three bars, filled up to the priority; urgent is a warning; none is a198
* quiet ellipsis. The label is its name for assistive technology and its tooltip. */199
export function PriorityMark({ priority }: { priority: Priority }) {200
const { label } = priorityOf(priority);201
const filled = priority === "high" ? 3 : priority === "medium" ? 2 : priority === "low" ? 1 : 0;202
return (203
<span role="img" aria-label={`Priority: ${label}`} title={label} className="flex size-4 shrink-0 items-center justify-center">204
{priority === "urgent" ? (205
<Warning weight="fill" className="size-4 text-orange" aria-hidden />206
) : priority === "none" ? (207
<DotsThree weight="bold" className="size-4 text-ink-3" aria-hidden />208
) : (209
<span className="flex h-3 items-end gap-0.5" aria-hidden>210
{[6, 9, 12].map((h, i) => <span key={h} className={`w-[3px] rounded-[1px] ${i < filled ? "bg-ink-2" : "bg-line-strong"}`} style={{ height: h }} />)}211
</span>212
)}213
</span>214
);215
}216
217
/** The assignee's avatar, or an empty circle; the name is its label and tooltip. 20px by default218
* (Linear's): in a list column a 24px coloured disc outweighs the issue titles. */219
export function AssigneeMark({ id, size = "20" }: { id: string | null; size?: "20" | "24" }) {220
const person = personOf(id);221
if (person) return <span title={person.label} className="flex"><Avatar name={person.label} color={person.color} size={size} /></span>;222
return (223
<span role="img" aria-label="Unassigned" title="Unassigned" className={`flex items-center justify-center rounded-full border border-dashed border-line-strong text-ink-3 ${size === "24" ? "size-6" : "size-5"}`}>224
<User weight="bold" className="size-3" aria-hidden />225
</span>226
);227
}228
229
type RowProps = { issue: Issue; open: boolean; picked: boolean; onOpen: (id: string) => void; onPick: (id: string, on: boolean) => void };230
231
/** One issue on one line: a click anywhere but the checkbox opens it; the title link is the232
* keyboard's way in (Enter). The open issue and picked rows are tinted, Linear's way. */233
function Row({ issue, open, picked, onOpen, onPick }: RowProps) {234
const status = statusOf(issue.status);235
return (236
<TableRow onClick={() => onOpen(issue.id)} className={`group/row cursor-default ${picked ? "bg-accent-tint" : open ? "bg-hover" : ""}`} data-issue={issue.id}>237
<TableCell className="pe-0 ps-4" onClick={(e) => e.stopPropagation()}>238
{/* hidden until the row is hovered or focused, or any row is picked; always on a touch screen */}239
<span className="flex opacity-0 group-hover/row:opacity-100 group-data-picking/list:opacity-100 focus-within:opacity-100 pointer-coarse:opacity-100">240
<Checkbox aria-label={`Select ${issue.id}`} checked={picked} onCheckedChange={(on) => onPick(issue.id, on === true)} />241
</span>242
</TableCell>243
<TableCell className="px-2"><PriorityMark priority={issue.priority} /></TableCell>244
<TableCell className="ps-0 font-mono text-xs text-ink-2">{issue.id}</TableCell>245
<TableCell truncate>246
<Link247
href={`#${issue.id}`} variant="standalone" tone="neutral" aria-current={open || undefined}248
onClick={(e) => { e.preventDefault(); e.stopPropagation(); onOpen(issue.id); }}249
>250
{issue.title}251
</Link>252
</TableCell>253
<TableCell className="hidden @4xl:table-cell">254
<span className="flex justify-end gap-1">{issue.labels.map((l) => <Tag key={l} size="sm" variant="outline" tone={toneOf(l)}>{l}</Tag>)}</span>255
</TableCell>256
<TableCell><StatusPill size="sm" tone={status.tone}>{status.label}</StatusPill></TableCell>257
<TableCell className="hidden pe-4 @xl:table-cell @2xl:pe-3"><AssigneeMark id={issue.assignee} /></TableCell>258
<TableCell numeric className={`hidden pe-4 @2xl:table-cell ${overdue(issue) ? "text-red" : issue.due ? "text-ink-2" : "text-ink-3"}`}>259
{issue.due ? shortDate(issue.due) : "—"}260
</TableCell>261
</TableRow>262
);263
}264
265
type PhoneRowProps = { issue: Issue; selecting: boolean; picked: boolean; onOpen: (id: string) => void; onPick: (id: string, on: boolean) => void };266
267
/** A phone's list row: ID, status and assignee on the first line, the title whole under it. In268
* select mode a tap picks the row instead of opening it. */269
function PhoneRow({ issue, selecting, picked, onOpen, onPick }: PhoneRowProps) {270
const status = statusOf(issue.status);271
return (272
<li className={`relative border-b border-line-soft ${picked ? "bg-accent-tint" : ""}`} data-issue={issue.id}>273
<div className="flex items-start gap-3 px-3 py-2.5" onClick={selecting ? () => onPick(issue.id, !picked) : undefined}>274
{selecting && (275
<span className="flex h-5 items-center" onClick={(e) => e.stopPropagation()}>276
<Checkbox aria-label={`Select ${issue.id}`} checked={picked} onCheckedChange={(on) => onPick(issue.id, on === true)} />277
</span>278
)}279
<span className="flex min-w-0 flex-1 flex-col gap-1">280
<span className="flex items-center gap-2">281
<PriorityMark priority={issue.priority} />282
<span className="font-mono text-xs text-ink-2">{issue.id}</span>283
<span className="ms-auto flex items-center gap-2">284
<StatusPill size="sm" tone={status.tone}>{status.label}</StatusPill>285
<AssigneeMark id={issue.assignee} size="20" />286
</span>287
</span>288
{selecting ? (289
<span className="text-sm font-medium text-ink wrap-break-word [unicode-bidi:plaintext]">{issue.title}</span>290
) : (291
<Link292
href={`#${issue.id}`} variant="standalone" tone="neutral" className="text-sm wrap-break-word [unicode-bidi:plaintext] after:absolute after:inset-0 after:content-['']"293
onClick={(e) => { e.preventDefault(); onOpen(issue.id); }}294
>295
{issue.title}296
</Link>297
)}298
</span>299
</div>300
</li>301
);302
}1
/* "New issue": a form in a dialog. The title is required; Enter in it creates the issue. The2
* buttons are the dialog's footer (Cancel, then the primary "Create issue"), tied to the form by3
* its id, so the form body keeps the dialog's padding and the footer its own band. */4
import { useState } from "react";5
import { Button, Combobox, Dialog, Field, Input, Select, Textarea } from "@fndn/react";6
import { ME, PEOPLE, PRIORITIES, PROJECTS, STATUSES, type Issue, type Priority, type Status } from "./data";7
8
export type Draft = Pick<Issue, "project" | "title" | "description" | "status" | "priority" | "assignee">;9
10
type Props = { open: boolean; onOpenChange: (open: boolean) => void; project: string; onCreate: (draft: Draft) => void };11
12
const FORM = "new-issue-form";13
const blank = (project: string): Draft => ({ project, title: "", description: "", status: "todo", priority: "none", assignee: ME.value });14
15
export function NewIssue({ open, onOpenChange, project, onCreate }: Props) {16
const [draft, setDraft] = useState<Draft>(() => blank(project));17
/* every new issue starts from a blank form: reset while rendering the opening, so its first18
* frame is already blank */19
const [wasOpen, setWasOpen] = useState(open);20
if (open !== wasOpen) { setWasOpen(open); if (open) setDraft(blank(project)); }21
return (22
<Dialog23
open={open} onOpenChange={onOpenChange} title="New issue" size="md" initialFocus="input[name=title]"24
footer={(25
<>26
<Button type="button" variant="secondary" size="sm" onClick={() => onOpenChange(false)}>Cancel</Button>27
<Button type="submit" form={FORM} variant="primary" size="sm" disabled={!draft.title.trim()}>Create issue</Button>28
</>29
)}30
>31
{open && <Form draft={draft} onDraftChange={setDraft} onCreate={onCreate} />}32
</Dialog>33
);34
}35
36
function Form({ draft, onDraftChange, onCreate }: { draft: Draft; onDraftChange: (d: Draft) => void; onCreate: (draft: Draft) => void }) {37
const set = (patch: Partial<Draft>) => onDraftChange({ ...draft, ...patch });38
return (39
<form id={FORM} className="flex flex-col gap-4" onSubmit={(e) => { e.preventDefault(); if (draft.title.trim()) onCreate({ ...draft, title: draft.title.trim() }); }}>40
<Field label="Title" required>41
<Input name="title" placeholder="Webhook deliveries time out after 10 s" value={draft.title} onChange={(e) => set({ title: e.target.value })} />42
</Field>43
<Field label="Description">44
<Textarea autoResize placeholder="What happens, and what should happen instead" value={draft.description} onChange={(e) => set({ description: e.target.value })} />45
</Field>46
<div className="grid grid-cols-2 gap-3 max-sm:grid-cols-1">47
<Select label="Project" items={PROJECTS} value={draft.project} onValueChange={(v) => v && set({ project: v })} />48
<Combobox label="Assignee" items={[{ value: "unassigned", label: "Unassigned" }, ...PEOPLE]} value={draft.assignee ?? "unassigned"} onValueChange={(v) => v && set({ assignee: v === "unassigned" ? null : v })} />49
<Select label="Status" items={STATUSES.map((s) => ({ value: s.value, label: s.label }))} value={draft.status} onValueChange={(v) => v && set({ status: v as Status })} />50
<Select label="Priority" items={PRIORITIES.map((p) => ({ value: p.value, label: p.label }))} value={draft.priority} onValueChange={(v) => v && set({ priority: v as Priority })} />51
</div>52
</form>53
);54
}1
/* A project's settings: General (name, identifier, default assignee; a save that is enabled once2
* something changed) with a danger zone, and Notifications (switches that apply at once). */3
import { useState, type ReactNode } from "react";4
import {5
AlertDialog, Button, Card, CardBody, CardDescription, CardHeader, CardTitle, Field, Input, PageHeader, ScrollArea, Select, Switch, Tabs, toast,6
} from "@fndn/react";7
import { PEOPLE, type Project } from "./data";8
9
const ASSIGNEES = [{ value: "none", label: "No one" }, ...PEOPLE.map((p) => ({ value: p.value, label: p.label }))];10
11
/** A setting: its name and what it does, the control at the end; wraps under the text when narrow. */12
const Row = ({ title, hint, children }: { title: string; hint: string; children: ReactNode }) => (13
<CardBody className="flex flex-wrap items-center justify-between gap-x-6 gap-y-2 border-b border-line-soft last:border-0">14
<div className="flex min-w-[200px] flex-1 flex-col gap-0.5"><span className="text-ink">{title}</span><span className="text-sm text-ink-2">{hint}</span></div>15
{children}16
</CardBody>17
);18
19
type Props = { project: Project; issueCount: number; onRename: (label: string, key: string) => void; onArchive: () => void; onDelete: () => void };20
21
export function Settings({ project, issueCount, onRename, onArchive, onDelete }: Props) {22
const [tab, setTab] = useState("general");23
const [name, setName] = useState(project.label);24
const [key, setKey] = useState(project.key);25
const [assignee, setAssignee] = useState("none");26
const [saved, setSaved] = useState({ name: project.label, key: project.key, assignee: "none" });27
const [notify, setNotify] = useState({ assigned: true, mentions: true, status: false, digest: true });28
const [confirm, setConfirm] = useState(false);29
30
const keyError = /^[A-Z]{2,5}$/.test(key) ? undefined : "2 to 5 capital letters, such as WEB.";31
const dirty = name !== saved.name || key !== saved.key || assignee !== saved.assignee;32
const save = () => {33
setSaved({ name, key, assignee });34
onRename(name.trim(), key);35
toast({ title: "Project settings saved", tone: "green", duration: 3000 });36
};37
38
const general = (39
<div className="flex flex-col gap-4">40
<Card>41
<CardHeader><CardTitle>Project</CardTitle><CardDescription>How {saved.name} appears across Northwind.</CardDescription></CardHeader>42
<CardBody>43
<form className="flex max-w-96 flex-col gap-4" onSubmit={(e) => { e.preventDefault(); if (dirty && !keyError && name.trim()) save(); }}>44
<Field label="Name" required invalid={!name.trim()} error={name.trim() ? undefined : "A project needs a name."}>45
<Input value={name} onChange={(e) => setName(e.target.value)} />46
</Field>47
<Field label="Identifier" helper={`Issue IDs start with it: ${key || "WEB"}-482.`} invalid={!!keyError} error={keyError}>48
<Input mono value={key} maxLength={5} onChange={(e) => setKey(e.target.value.toUpperCase())} />49
</Field>50
<Select label="Default assignee" items={ASSIGNEES} value={assignee} onValueChange={(v) => setAssignee(v ?? "none")} />51
<div className="flex gap-2">52
<Button type="submit" variant="primary" size="sm" disabled={!dirty || !!keyError || !name.trim()}>Save changes</Button>53
{dirty && <Button type="button" variant="secondary" size="sm" onClick={() => { setName(saved.name); setKey(saved.key); setAssignee(saved.assignee); }}>Discard</Button>}54
</div>55
</form>56
</CardBody>57
</Card>58
{/* the danger zone says so by its title and its red-outlined buttons (GitHub's): the filled59
red is kept for the confirm dialog, where the deletion is decided */}60
<Card data-app="danger-zone">61
<CardHeader><CardTitle className="text-red">Danger zone</CardTitle></CardHeader>62
<Row title="Archive project" hint="Hide it from the sidebar. Its issues stay searchable and you can restore it.">63
<Button size="sm" variant="danger-outline" onClick={onArchive}>Archive</Button>64
</Row>65
<Row title="Delete project" hint={`Remove ${saved.name} and its ${issueCount === 1 ? "issue" : `${issueCount} issues`} for everyone. This cannot be undone.`}>66
<AlertDialog67
open={confirm} onOpenChange={setConfirm} tone="danger"68
trigger={<Button size="sm" variant="danger-outline">Delete project</Button>}69
title={`Delete ${saved.name}?`}70
description={`Its ${issueCount === 1 ? "issue" : `${issueCount} issues`}, comments and activity are deleted for everyone in Northwind. This cannot be undone.`}71
actionLabel="Delete project"72
onAction={onDelete}73
/>74
</Row>75
</Card>76
</div>77
);78
79
const set = (k: keyof typeof notify) => (on: boolean) => setNotify((n) => ({ ...n, [k]: on }));80
const notifications = (81
<Card>82
<CardHeader><CardTitle>Notify me about</CardTitle><CardDescription>In your inbox, and by email to maya@northwind.example.</CardDescription></CardHeader>83
<Row title="Issues assigned to me" hint="When someone assigns you or reassigns your issue."><Switch label="Issues assigned to me" checked={notify.assigned} onCheckedChange={set("assigned")} /></Row>84
<Row title="Mentions" hint="When someone writes @maya in a comment."><Switch label="Mentions" checked={notify.mentions} onCheckedChange={set("mentions")} /></Row>85
<Row title="Status changes" hint="On issues you created."><Switch label="Status changes" checked={notify.status} onCheckedChange={set("status")} /></Row>86
<Row title="Weekly digest" hint="Every Monday at 9:00: what moved in this project."><Switch label="Weekly digest" checked={notify.digest} onCheckedChange={set("digest")} /></Row>87
</Card>88
);89
90
return (91
<ScrollArea className="h-full">92
<div className="mx-auto flex max-w-[720px] flex-col gap-4 px-6 py-6 max-sm:px-3 max-sm:py-4" data-app="settings">93
<PageHeader title="Settings" />94
<Tabs95
aria-label="Settings" value={tab} onValueChange={setTab}96
items={[97
{ value: "general", label: "General", content: general },98
{ value: "notifications", label: "Notifications", content: notifications },99
]}100
/>101
</div>102
</ScrollArea>103
);104
}1
import { useCallback, useRef, useState } from "react";2
3
/** The width of an element (a callback ref: the element may come and go), measured before the4
* first paint and on every change. */5
export function useWidth() {6
const [width, setWidth] = useState(0);7
const observer = useRef<ResizeObserver>(null);8
const ref = useCallback((el: HTMLElement | null) => {9
observer.current?.disconnect();10
if (!el) return;11
setWidth(el.clientWidth);12
observer.current = new ResizeObserver(([e]) => e && setWidth(e.contentRect.width));13
observer.current.observe(el);14
}, []);15
return [ref, width] as const;16
}