import Link from "next/link"; import { UndoBar, LifecycleButton } from "@/components/piece/Lifecycle"; import Menu from "@/components/piece/Menu"; import FilterSheet from "@/components/shell/FilterSheet"; import SlashFocus from "@/components/shell/SlashFocus"; import AppShell from "@/components/shell/AppShell"; import { badgeVariants } from "@/components/ui/badge"; import { buttonVariants } from "@/components/ui/button"; import { EmptyState } from "@/components/ui/empty-state"; import { Input } from "@/components/ui/field"; import { LitList } from "@/components/ui/lit-list"; import { LitActions, LitGroup, LitLine } from "@/components/ui/lit-line"; import { Toolbar, ToolbarGroup } from "@/components/ui/toolbar"; import { createHref, siteHref, workHref, type WorkQuery } from "@/lib/hrefs"; import { ARTICLES_KEY } from "@/lib/articles/key.mjs"; import { KINDS } from "@/lib/projects"; import { readWork, type WorkRow } from "@/lib/work"; import { privateFilter } from "@/lib/privacy"; import { LIFECYCLES, STAGES, keepRow, lifeFilter, sortRows } from "@/lib/work/facets.mjs"; import { cn } from "@/lib/utils"; export const dynamic = "force-dynamic"; // --------------------------------------------------------------------------- // WORK (plans/umtool-redesign.md, P3; canvas "Work"): every piece in one lit // list -- an article with its video projects, or a project no article claims. // Facets: stage, kind, site, lifecycle (active by default), recurring (R5: the // series and the living reports, each with its cadence chip), and a search. It // replaced three lists, and reads their keys (lib/work/facets.mjs): /browse's // (kind, template, state, open, sort), /articles' (status, notes, audience) // and /sites' (site; `by=site` groups by site). A key with no chip of its own // shows as a chip you can take off. // // The facets are links that change searchParams and the search is a GET form, // so any view is one pasteable URL. The rows' lifecycle menus are the only // client JS beyond the lit list. // // A row's Park / Mark done sit behind its own ⋯ menu, never on the line: a // lit line's actions are clickable before they are drawn, and on a phone the // buttons landed on the stage pips, so a tap on the row marked a piece done. // // ON A PHONE (below md; the desk unchanged) a row is a CARD: the title (two // lines at most), `kind · site` in mono, the stage pips and the stage's word. // A tap anywhere on it opens the piece, and it carries NO lifecycle control -- // that is the piece's ⋯ sheet, with its Undo. No table head (it overprinted). // The facets fold into one summary line that opens them in a sheet // (FilterSheet.tsx); the search stays in flow. // --------------------------------------------------------------------------- type Search = { [K in keyof WorkQuery]?: string }; const STAGE_LABEL: Record = { research: "Research", article: "Article", video: "Video", deliver: "Deliver" }; const LIFE_LABEL: Record = { active: "Active", parked: "Parked", done: "Done" }; /** Keys from the old lists that Work filters on but has no chip group for. */ const EXTRA: { key: keyof Search; label: string }[] = [ { key: "template", label: "template" }, { key: "state", label: "state" }, { key: "open", label: "decisions" }, { key: "status", label: "status" }, { key: "notes", label: "notes" }, { key: "audience", label: "audience" }, ]; export default async function WorkPage({ searchParams }: { searchParams: Promise }) { const sp = await searchParams; const { rows: read, lifecycleError } = await readWork(); // settings.privacy.hidePrivateSites: the rows DRAWN leave out a private // site's pieces and the projects they own (readWork itself stays whole). const hide = await privateFilter(); const all = hide ? read.filter((r) => !hide.pieces.has(r.id) && !(r.project && hide.projects.has(r.project))) : read; const q = sp as Record; const shown = sortRows( all.filter((r) => keepRow(r, q)), sp.sort, ) as WorkRow[]; const life = lifeFilter(sp.life); // A chip's count: how many pieces that chip would show, the other facets kept. const n = (over: Partial) => all.filter((r) => keepRow(r, { ...q, ...over })).length; const href = (next: Partial) => workHref({ ...sp, deleted: undefined, freed: undefined, ...next }); const sites = [...new Set(all.map((r) => r.site).filter((s): s is string => !!s))].sort(); const kinds = [{ id: "article", label: "Article" }, { id: "series", label: "Series" }, { id: "watch", label: "Watch" }, ...KINDS.map((k) => ({ id: k.id, label: k.label }))].filter( (k) => all.some((r) => r.kinds.includes(k.id)), ); const bySite = sp.by === "site"; // The phone's one line for the facets: "Active · any stage · any kind". const summary = [ life ? LIFE_LABEL[life] : "Every lifecycle", sp.stage ? STAGE_LABEL[sp.stage] ?? sp.stage : "any stage", sp.kind ? (kinds.find((k) => k.id === sp.kind)?.label ?? sp.kind) : "any kind", ...(sp.site ? [sp.site] : []), ...(sp.recurring === "1" ? ["recurring"] : []), ...EXTRA.filter((e) => sp[e.key]).map((e) => `${e.label}: ${sp[e.key]}`), ].join(" · "); const groups = bySite ? groupBySite(shown) : [{ key: "", title: null as React.ReactNode, rows: shown }]; return (
{shown.length} piece{shown.length === 1 ? "" : "s"} shown · {life ?? "every lifecycle"} } actions={ // One way in to everything that can be made (canvas "Work"): /create. + Create } /> {/* A GET form, so a search is a pasteable URL; the other keys ride along. */}
{(Object.keys(sp) as (keyof Search)[]) .filter((k) => k !== "q" && k !== "deleted" && k !== "freed" && sp[k]) .map((k) => ( ))} {/* No `/` key on a phone; kbd's own display is unlayered, so the span hides it. */} {sp.q && ( clear )}
{STAGES.map((s) => ( ))} {kinds.map((k) => ( ))} {LIFECYCLES.map((l) => ( ))} {sites.map((s) => ( ))} {sp.site && sp.site !== ARTICLES_KEY && ( site page → )} {/* The recurring reports (R5): the series and the living reports. */} {EXTRA.some((e) => sp[e.key]) && ( {EXTRA.filter((e) => sp[e.key]).map((e) => ( {e.label}: {sp[e.key]} × ))} )}
{sp.deleted && (

Deleted {sp.deleted} {Number(sp.freed) > 0 ? ` (${(Number(sp.freed) / 1024 / 1024).toFixed(1)} MiB)` : ""}.

)} {lifecycleError && (

{lifecycleError} — every piece reads as active until it is fixed.

)} {shown.length === 0 ? ( ) : ( <>
Piece Stage Kind Lifecycle Open
{groups.map((g) => g.title ? ( {g.rows.map((r) => ( ))} ) : ( g.rows.map((r) => ) ), )} )}
); } function groupBySite(rows: WorkRow[]): { key: string; title: React.ReactNode; rows: WorkRow[] }[] { const by = new Map(); for (const r of rows) { const k = r.site ?? ""; by.set(k, [...(by.get(k) ?? []), r]); } return [...by.entries()] .sort(([a], [b]) => (a === "" ? 1 : b === "" ? -1 : a.localeCompare(b))) .map(([key, list]) => ({ key: key || "projects", title: key && key !== ARTICLES_KEY ? ( {key} ) : ( key || "projects" ), rows: list, })); } /** The list's columns on the desk; below md a row is a card (one column). */ const COLS = "grid grid-cols-[minmax(0,1fr)] md:grid-cols-[minmax(0,1fr)_190px_160px_130px_56px]"; function Row({ r }: { r: WorkRow }) { return (
{/* On a phone the link covers the card (its ::after), so a tap anywhere opens the piece. */} {r.title} {[r.kindLabel, r.site, r.lifecycle !== "active" ? r.lifecycle : null].filter(Boolean).join(" · ")} {r.chip && {r.chip}} {r.id} {r.chip && ( {r.chip} )}
{Array.from({ length: r.steps }, (_, k) => k + 1).map((i) => ( ))} {r.stageLabel} {r.kindLabel} {r.lifecycle} {r.lifecycle === "active" && r.looksDone.length > 0 && · looks done} {r.counts.calls || "—"}
); } function Chip({ href, on, label, n }: { href: string; on: boolean; label: string; n?: number }) { return ( {label} {n !== undefined && {n}} ); }