sections.ts
This file
Path
apps/web/src/features/shared/shell/sections.ts
289 lines · 7.9 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 1–2why, one step back1import { projectAddressOf } from "@repo/protocol/ids";2import { Option } from "effect";Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 3why, one step back3Merge redesign into mainoscabrielbefore adoptioncaedd21
line 4why, one step back4import { INBOX_PATH, segmentsOf } from "../paths.ts";Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 5why, one step back5Merge redesign into mainoscabrielbefore adoptioncaedd21
line 6why, one step back6/** A project's eight tabs (ADR 0041), in the header's order. */Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 7why, one step back7export type ProjectTab =Merge redesign into mainoscabrielbefore adoptioncaedd21
line 8why, one step back8 | "asks"Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 9–12why, one step back9 | "code"10 | "landings"11 | "overview"12 | "people"Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 13–15why, one step back13 | "policy"14 | "proposals"15 | "visibility";Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 16–20why, one step back1617export interface Section {18 readonly label: string;19 readonly tab: ProjectTab;20 readonly to: string;Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 21–22why, one step back21 /** A tab whose own page has not been built yet opens the region of Overview that holds it. */22 readonly hash?: string;Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 23–24why, one step back23}24Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 25–31why, one step back25/**26 * Each tab opens a page inside the project's frame that exists today: Asks,27 * Landings, Proposals and People open their regions of Overview (the history28 * of commits is the Code tab's), Policy the policy at the address it has29 * always had, and Visibility its own page. Starting a30 * proposal is a focused page of its own, so it is Contribute's, not a tab's.31 */Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 32why, one step back32export const projectSections = (project: string): readonly Section[] => [Merge redesign into mainoscabrielbefore adoptioncaedd21
line 33why, one step back33 { label: "Overview", tab: "overview", to: `/${project}` },Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 34why, one step back34 { label: "Code", tab: "code", to: `/${project}/tree/main` },Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 35–50why, one step back35 { hash: "open-asks", label: "Asks", tab: "asks", to: `/${project}` },36 {37 hash: "recent-landings",38 label: "Landings",39 tab: "landings",40 to: `/${project}`,41 },42 {43 hash: "proposals",44 label: "Proposals",45 tab: "proposals",46 to: `/${project}`,47 },48 { hash: "who-decides", label: "People", tab: "people", to: `/${project}` },49 { label: "Policy", tab: "policy", to: `/${project}/people` },50 { label: "Visibility", tab: "visibility", to: `/${project}/visibility` },Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 51–52why, one step back51];52Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 53–88why, one step back53/** The tab each page of a project sits under, by its first segment. */54const TAB_OF = {55 answers: "landings",56 asks: "asks",57 blob: "code",58 commit: "code",59 commits: "code",60 decisions: "asks",61 people: "policy",62 proposals: "proposals",63 raw: "code",64 refs: "code",65 tree: "code",66 visibility: "visibility",67 why: "code",68} as const satisfies Record<string, ProjectTab>;6970/** A crumb names the page itself, which may be narrower than its tab. */71type PageSection =72 | "code"73 | "landings"74 | "overview"75 | "people"76 | "refs"77 | "visibility";7879const PAGE_TO = (project: string) =>80 ({81 code: `/${project}/tree/main`,82 landings: `/${project}/commits/main`,83 overview: `/${project}`,84 people: `/${project}/people`,85 refs: `/${project}/refs`,86 visibility: `/${project}/visibility`,87 }) as const satisfies Record<PageSection, string>;88Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 89–97why, one step back89const SECTION_OF = {90 answers: "overview",91 asks: "overview",92 blob: "code",93 commit: "landings",94 commits: "landings",95 people: "people",96 refs: "refs",97 tree: "code",Merge redesign into mainoscabrielbefore adoptioncaedd21
line 98why, one step back98 visibility: "visibility",Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 99why, one step back99 why: "code",Merge redesign into mainoscabrielbefore adoptioncaedd21
line 100why, one step back100} as const satisfies Record<string, PageSection>;Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 101why, one step back101Merge redesign into mainoscabrielbefore adoptioncaedd21
line 102why, one step back102const SITE = new Set(["agents", "asks", "docs", "import", "inbox", "people"]);Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 103why, one step back103Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 104–106why, one step back104const addressOf = (pathname: string) => {105 const segments = segmentsOf(pathname);106 const [first] = segments;Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 107why, one step back107Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 108–110why, one step back108 return first === undefined || SITE.has(first)109 ? undefined110 : Option.getOrUndefined(projectAddressOf(segments));Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 111–112why, one step back111};112Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 113–115why, one step back113export const projectOf = (pathname: string): string | undefined =>114 addressOf(pathname)?.spelled;115Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 116–117why, one step back116/** The tab a project's page sits under; Overview for the project's own address. */117export const projectTabOf = (pathname: string): ProjectTab | undefined => {Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 118why, one step back118 const address = addressOf(pathname);Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 119why, one step back119Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 120why, one step back120 if (address === undefined) {Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 121–123why, one step back121 return undefined;122 }123Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 124–126why, one step back124 const [page] = address.rest;125126 return page === undefinedPut every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 127why, one step back127 ? "overview"Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 128–161why, one step back128 : Object.entries(TAB_OF).find(([segment]) => segment === page)?.[1];129};130131/**132 * The pages under a project that its route draws in another shell: starting133 * a proposal is focused (`staticData.shell` is `focus`), so it has no header.134 */135const OUTSIDE_FRAME: readonly (readonly string[])[] = [["proposals", "new"]];136137/** Whether a path is a project's page drawn in the project's frame, under its header. */138export const inProjectFrame = (pathname: string): boolean => {139 const address = addressOf(pathname);140141 return (142 address !== undefined &&143 !OUTSIDE_FRAME.some(144 (page) =>145 page.length === address.rest.length &&146 page.every((segment, at) => address.rest[at] === segment)147 )148 );149};150151const sectionOf = (pathname: string): PageSection | undefined => {152 const address = addressOf(pathname);153154 if (address === undefined) {155 return undefined;156 }157158 const [page] = address.rest;159160 return page === undefined161 ? "overview"Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 162why, one step back162 : Object.entries(SECTION_OF).find(([segment]) => segment === page)?.[1];Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 163–176why, one step back163};164165export interface Crumb {166 readonly label: string;167 readonly mono?: boolean;168 readonly to?: string;169}170171const SECTION_LABEL = {172 code: "Code",173 landings: "Landings",174 overview: "Asks",175 people: "Policy",176 refs: "Refs",Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 177–178why, one step back177 visibility: "Visibility",178} as const satisfies Record<PageSection, string>;Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 179–181why, one step back179180const sectionCrumb = (181 project: string,Merge redesign into mainoscabrielbefore adoptioncaedd21
line 182why, one step back182 tab: PageSection,Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 183–186why, one step back183 below: boolean184): Crumb => {185 const label = SECTION_LABEL[tab];186Merge redesign into mainoscabrielbefore adoptioncaedd21
line 187why, one step back187 return below ? { label, to: PAGE_TO(project)[tab] } : { label };Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 188–191why, one step back188};189190const projectCrumbs = (191 project: string,Merge redesign into mainoscabrielbefore adoptioncaedd21
line 192why, one step back192 tab: PageSection,Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 193–204why, one step back193 below: boolean194): readonly Crumb[] => [195 { label: project, to: `/${project}` },196 sectionCrumb(project, tab, below),197];198199const pathCrumbs = (project: string, path: string): readonly Crumb[] =>200 path === ""201 ? projectCrumbs(project, "code", false)202 : [...projectCrumbs(project, "code", true), { label: path, mono: true }];203204const SITE_CRUMBS = {Merge build/1300-w13-foundation into mainoscabrielbefore adoption0e29c37
lines 205–209why, one step back205 asks: () => [{ label: "Asks" }],206 docs: (page: string | undefined) =>207 page === undefined208 ? [{ label: "Docs" }]209 : [{ label: "Docs", to: "/docs" }, { label: page }],Merge redesign into mainoscabrielbefore adoptioncaedd21
line 210why, one step back210 inbox: () => [{ label: "Inbox" }],Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 211–234why, one step back211 people: (handle: string | undefined) => [{ label: handle ?? "People" }],212} as const satisfies Record<213 string,214 (second: string | undefined) => readonly Crumb[]215>;216217const SUBJECT_CRUMBS = {218 answers: (project: string, ask: string) => [219 ...projectCrumbs(project, "overview", true),220 { label: ask, mono: true, to: `/${project}/asks/${ask}` },221 { label: "Answer" },222 ],223 asks: (project: string, ask: string) => [224 ...projectCrumbs(project, "overview", true),225 { label: ask, mono: true },226 ],227 blob: (project: string, _rev: string, path: string) =>228 pathCrumbs(project, path),229 commit: (project: string, sha: string) => [230 ...projectCrumbs(project, "landings", true),231 { label: sha.slice(0, 7), mono: true },232 ],233 decisions: (project: string, decision: string) => [234 { label: project, to: `/${project}` },Merge redesign into mainoscabrielbefore adoptioncaedd21
line 235why, one step back235 { label: "Inbox", to: INBOX_PATH },Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 236–251why, one step back236 { label: decision, mono: true },237 ],238 proposals: (project: string, proposal: string) => [239 ...projectCrumbs(project, "overview", true),240 proposal === "new" ? { label: "Propose" } : { label: proposal, mono: true },241 ],242 tree: (project: string, _rev: string, path: string) =>243 pathCrumbs(project, path),244 why: (project: string, _rev: string, path: string) =>245 pathCrumbs(project, path),246} as const satisfies Record<247 string,248 (project: string, third: string, rest: string) => readonly Crumb[]249>;250251export const crumbsFor = (pathname: string): readonly Crumb[] => {Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 252why, one step back252 const [first, second] = segmentsOf(pathname);Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 253–263why, one step back253254 if (first === undefined) {255 return [{ label: "Asks" }];256 }257258 const site = Object.entries(SITE_CRUMBS).find(([name]) => name === first);259260 if (site !== undefined) {261 return site[1](second);262 }263Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 264–272why, one step back264 const address = addressOf(pathname);265266 if (address === undefined) {267 return [{ label: first }];268 }269270 const project = address.spelled;271 const [page, third, ...rest] = address.rest;272Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 273why, one step back273 const subject = Object.entries(SUBJECT_CRUMBS).find(Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 274why, one step back274 ([name]) => name === pagePut every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 275–277why, one step back275 );276277 if (subject !== undefined && third !== undefined) {Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 278why, one step back278 return subject[1](project, third, rest.join("/"));Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 279–284why, one step back279 }280281 const tab = sectionOf(pathname);282283 return tab === undefined284 ? [Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
lines 285–286why, one step back285 { label: project, to: `/${project}` },286 { label: rest.at(-1) ?? third ?? page ?? project },Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 287why, one step back287 ]Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 288why, one step back288 : projectCrumbs(project, tab, false);Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 289why, one step back289};