import Link from "next/link"; import { Markdown } from "@/lib/markdown"; import { fmtAgo, fmtBytes } from "@/lib/format"; import type { OpenedFile, WorkspaceListing } from "@/lib/articles/files"; // The files an article was written from, and the one that is open. Zero JS: // each file is a link that sets `?ws=&rel=` on the page it sits on; markdown // renders, a draft's JSON is pretty-printed with each top-level key folded, // and HTML opens in a sandboxed iframe (no scripts, no same origin). export default function WorkspacePanel({ workspaces, opened, hrefFor, highlight, }: { workspaces: WorkspaceListing[]; opened: OpenedFile | null; hrefFor: (ws: string, rel: string) => string; /** A file to mark (the article's own draft), as `/`. */ highlight?: string | null; }) { if (workspaces.length === 0) return

no workspace found

; return (
{workspaces.map((w) => (
{w.dir}
    {w.files.map((f) => { const on = opened?.ws === w.name && opened.rel === f.rel; const mine = highlight === `${w.name}/${f.rel}`; return (
  • {f.rel} {mine && this article} {fmtBytes(f.bytes)} ยท {fmtAgo(f.mtimeMs)}
  • ); })}
))}
{opened ? :

pick a file

}
); } function Opened({ file }: { file: OpenedFile }) { const head =
{file.rel}
; if (file.kind === "error") { return (
{head}

{file.message}

); } if (file.kind === "html") { return (
{head}