Merge build/1412-lists-and-people into main
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by oscabriel · committed by oscabriel · parents 059c75c, 2bb32e1 · Browse files · 9 files·+316 added−51 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+316 added−51 removed
- tests:+209 added−26 removed
- other:+107 added−25 removed
Provenance
- Commit
3f8c8b9- Tree
b4449eb- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent 1
059c75c- Parent 2
2bb32e1
9 files changed+316 added−51 removed
modified:apps/web/src/features/landing/projects.ts+7 added-7 removed
123234567889910111112131415161718191920212223242425/** * The landing's projects block: the first few on the platform, or that the * list did not come. The read that fills it is `read.ts`'s. * The landing's projects block: the eight that lead (the most open asks * first, a tie by name), or that the list did not come. The read that * fills it is `read.ts`'s. */import { ProjectListing } from "@repo/protocol/domain/front-page";import { Schema } from "effect";
/** The projects the page names; the rest are a step away, at `/asks`. */export const PROJECTS_SHOWN = 8;import { leadingProjects, PROJECTS_SHOWN } from "../shared/project-order.ts";
/** The projects block: the first few on the platform, or that the list did not come. *//** The projects block: the ones that lead, or that the list did not come. */export const LandingProjects = Schema.TaggedUnion({ Listed: { projects: Schema.Array(ProjectListing) }, Unreachable: {},});
export type LandingProjects = typeof LandingProjects.Type;
/** The block from a list that came. *//** The block from a list that came: the eight that lead. */export const listedProjects = ( projects: readonly ProjectListing[]): LandingProjects => LandingProjects.cases.Listed.make({ projects: projects.slice(0, PROJECTS_SHOWN), projects: leadingProjects(projects, PROJECTS_SHOWN), });modified:apps/web/src/features/shared/shell/overlays.tsx+24 added-11 removed
135 unmodified lines136 </Combobox>137 );138 };139 140+/** The Projects sheet's body: the switcher, and the way to import a repo at its foot. */141+export const ProjectsSheetBody = ({142+ input,143+ onChosen,144+}: {145+ readonly input: RefObject<HTMLInputElement | null>;146+ readonly onChosen: () => void;147+}) => (148+ <>149+ <ProjectSwitcher input={input} onChosen={onChosen} />150+ <div className="border-rule border-t p-1">151+ <AppLink className={RAIL_ROW} to={IMPORT_PATH}>152+ <FolderInput153+ aria-hidden="true"154+ className="text-muted-foreground size-4 shrink-0"155+ strokeWidth={1.75}156+ />157+ Import a repo158+ </AppLink>159+ </div>160+ </>161+);162+163 /** The phone's More: Docs, For agents, the project's sections, the keys, the session. */164 const More = () => {165 const project = useCurrentProject();166 const listed = useProjectList();118 unmodified lines285 initialFocus={filter}286 side={overlay === "projects" && atLeastTablet() ? "left" : "full"}287 title="Projects"288 >266- <ProjectSwitcher input={filter} onChosen={onClose} />267- <div className="border-rule border-t p-1">268- <AppLink className={RAIL_ROW} to={IMPORT_PATH}>269- <FolderInput270- aria-hidden="true"271- className="text-muted-foreground size-4 shrink-0"272- strokeWidth={1.75}273- />274- Import a repo275- </AppLink>276- </div>289+ <ProjectsSheetBody input={filter} onChosen={onClose} />290 </SheetContent>291 </Sheet>292 <KeysDialog onClose={onClose} open={overlay === "keys"} />293 </>4 unmodified linesmodified:apps/web/src/features/shared/shell/rail.tsx+7 added-7 removed
37 unmodified lines38 import { postureLabel, postureWord } from "../../project/posture-label.ts";39 import { AppLink } from "../link.tsx";40 import { POSTURE_MARKS } from "../mark-look.ts";41 import { ASKS_PATH, docsPath, HOME_PATH } from "../paths.ts";42+import { leadingProjects, PROJECTS_SHOWN } from "../project-order.ts";43 import {44 useCurrentProject,45 useProjectList,46 useShell,11 unmodified lines58 59 /** A row's mark: 16 px at the marks' stroke, muted until the row is current. */60 const MARK = "text-muted-foreground size-4 shrink-0";61 61-/** At most this many projects in the rail; more open the switcher. */62-const SHOWN = 8;63-62 const SITE = [63 { icon: House, label: "Home", to: HOME_PATH },64 { icon: List, label: "Asks", to: ASKS_PATH },65 { icon: CalendarCheck, label: "Today", to: "/today" },152 unmodified lines218 );219 220 /**221 * The projects: the current one first, its sections under it, so the list224- * arriving after the page moves nothing above it; then the others, up to225- * eight in all, and the switcher for the rest.222+ * arriving after the page moves nothing above it; then the others that223+ * lead (the most open asks first, a tie by name), up to eight in all, and224+ * the switcher for the rest.225 */226 const Projects = () => {227 const current = useCurrentProject();228 const listed = useProjectList();2 unmodified lines231 const listingOf = (project: string) =>232 listed?.find((listing) => listing.project === project);233 234 const others = (listed ?? []).filter(({ project }) => project !== current);236- const room = SHOWN - (current === undefined ? 0 : 1);235+ const room = PROJECTS_SHOWN - (current === undefined ? 0 : 1);236+ const leading = leadingProjects(others, room);237 238 return (239 <div className="flex flex-col gap-1">240 <h2 className="text-label text-muted-foreground px-2 pt-4 pb-1">15 unmodified lines256 )}257 {listed === undefined ? (258 <PlaceholderRows />259 ) : (260- others.slice(0, room).map((listing) => (260+ leading.map((listing) => (261 <li key={listing.project}>262 <ProjectRow263 current={false}264 listing={listing}154 unmodified linesadded:apps/web/src/features/shared/project-order.ts+26 added
1234567891011121314151617181920212223242526/** * Which projects a short list names: the rail's and the * landing's. The ones with the most open asks lead, a tie by name, so a * reader meets first the projects with work to take. The platform's own * list keeps its order; this is the web's. */import type { ProjectListing } from "@repo/protocol/domain/front-page";import { Array as Arr, Order } from "effect";
/** How many projects the rail and the landing name; the rest are a step away. */export const PROJECTS_SHOWN = 8;
/** The most open asks first, then by name. */const leading = Order.combine( Order.mapInput( Order.flip(Order.Number), ({ openAsks }: ProjectListing) => openAsks ), Order.mapInput(Order.String, ({ project }: ProjectListing) => project));
/** The `n` projects that lead: the most open asks first, a tie by name. */export const leadingProjects = ( projects: readonly ProjectListing[], n: number): readonly ProjectListing[] => Arr.take(Arr.sort(projects, leading), n);added:apps/web/src/routes/$owner/index.tsx+43 added
12345678910111213141516171819202122232425262728293031323334353637383940414243import { Handle, reservedProjectNames } from "@repo/protocol/ids";import { createFileRoute, notFound, redirect } from "@tanstack/react-router";import { Effect, Option, Schema } from "effect";
import { personPath } from "../../features/shared/paths.ts";
// `/<owner>` alone: a handle leads to the person's page,// `/people/<handle>` in lowercase (handles compare without case), by a// 302, since the address may yet hold a page of its own. An owner that is// no handle (a source host, `/github.com`) and a word the web keeps for// itself (`/icons`) are not found.
const decodeHandle = Schema.decodeOption(Handle);
const isReserved = (owner: string) => reservedProjectNames.some((reserved) => reserved === owner.toLowerCase());
/** * The redirect to the person's page, or a 404, as the loader's rejection: * the router reads either from a failed load (the lint keeps a bare * `throw` for `Error`s, which neither is). */export const ownerLoader = ({ params,}: { readonly params: { readonly owner: string };}): Promise<never> => Effect.runPromise( Option.match( isReserved(params.owner) ? Option.none() : decodeHandle(params.owner.toLowerCase()), { onNone: () => Effect.fail(notFound()), onSome: (handle) => Effect.fail(redirect({ href: personPath(handle), statusCode: 302 })), } ) );
export const Route = createFileRoute("/$owner/")({ loader: ownerLoader,});modified:apps/web/test/landing.test.tsx+16 added-26 removed
12 unmodified lines13 import { ProjectListing } from "@repo/protocol/domain/front-page";14 import { Effect, Schema } from "effect";15 16 import { LandingView } from "../src/features/landing/landing-page.tsx";17-import {18- LandingProjects,19- PROJECTS_SHOWN,20-} from "../src/features/landing/projects.ts";17+import { LandingProjects } from "../src/features/landing/projects.ts";18 import { readLandingProjects } from "../src/features/landing/read.ts";19 import { LEDE } from "../src/features/landing/words.ts";20 import { landingHead } from "../src/routes/index.tsx";21+import { EIGHT_LEADING, TEN_LISTED } from "./listings.ts";22 import { textIn } from "./markup.ts";23 import { platformWith, unreachablePlatform } from "./platform.ts";24 import { renderAt } from "./render.tsx";25 173 unmodified lines199 Contracts.toLayerHandler("listProjects", () => Effect.succeed({ projects }))200 );201 202 describe("the landing's projects, read on the server", () => {205- const many = Schema.decodeSync(Schema.Array(ProjectListing))(206- Array.from({ length: PROJECTS_SHOWN + 2 }, (_, at) => ({207- openAsks: 1,208- posture: "open",209- project: `oscabriel/project-${at}`,210- }))211- );203+ it.effect(204+ "names eight, the most open asks first and a tie by name, each by its full name",205+ () =>206+ Effect.gen(function* () {207+ const read = yield* readLandingProjects.pipe(208+ Effect.provide(listing(TEN_LISTED))209+ );210 213- it.effect("names the first eight projects the platform lists", () =>214- Effect.gen(function* () {215- const read = yield* readLandingProjects.pipe(216- Effect.provide(listing(many))217- );218-219- expect(220- LandingProjects.match(read, {221- Listed: ({ projects }) => projects.map(({ project }) => project),222- Unreachable: () => [],223- })224- ).toStrictEqual(225- many.slice(0, PROJECTS_SHOWN).map(({ project }) => project)211+ expect(212+ LandingProjects.match(read, {213+ Listed: ({ projects }) => projects.map(({ project }) => project),214+ Unreachable: () => [],215+ })216+ ).toStrictEqual(EIGHT_LEADING);217+ })226- );227- })218 );219 220 it.effect("says so, and never fails, when the platform did not answer", () =>221 Effect.gen(function* () {8 unmodified linesadded:apps/web/test/listings.ts+32 added
1234567891011121314151617181920212223242526272829303132/** * Ten listed projects, as the platform lists them (in no order the page * keeps), two pairs tied on open asks, and the eight that lead: the most * open asks first, a tie by name. */import { ProjectListing } from "@repo/protocol/domain/front-page";import { Schema } from "effect";
export const TEN_LISTED = Schema.decodeSync(Schema.Array(ProjectListing))([ { openAsks: 1, posture: "open", project: "oscabriel/alpha" }, { openAsks: 5, posture: "open", project: "oscabriel/datekit" }, { openAsks: 0, posture: "open", project: "oscabriel/zeta" }, { openAsks: 9, posture: "open", project: "oscabriel/burrow" }, { openAsks: 3, posture: "open", project: "oscabriel/kite" }, { openAsks: 5, posture: "open", project: "github.com/pallets/click" }, { openAsks: 0, posture: "open", project: "oscabriel/yarrow" }, { openAsks: 2, posture: "open", project: "github.com/sindresorhus/ky" }, { openAsks: 3, posture: "open", project: "oscabriel/hearth" }, { openAsks: 7, posture: "open", project: "oscabriel/ember" },]);
/** The eight of `TEN_LISTED` that lead, in order. */export const EIGHT_LEADING = [ "oscabriel/burrow", "oscabriel/ember", "github.com/pallets/click", "oscabriel/datekit", "oscabriel/hearth", "oscabriel/kite", "github.com/sindresorhus/ky", "oscabriel/alpha",] as const;added:apps/web/test/owner-route.test.ts+88 added
1+/**2+ * An owner's address alone: `/<handle>` leads to the person's page,3+ * `/people/<handle>` in lowercase (handles compare without case), by a 3024+ * (a handle may yet become a page of its own); an owner that is no handle,5+ * a source host among them, and a word the web keeps for itself are not6+ * found. The app's own router reaches the route for `/<handle>` and still7+ * reaches its own pages by their words.8+ */9+import { describe, expect, it } from "@effect/vitest";10+import { reservedProjectNames } from "@repo/protocol/ids";11+import { isNotFound, isRedirect } from "@tanstack/react-router";12+import { Effect } from "effect";13+14+import { getRouter } from "../src/router.tsx";15+import {16+ ownerLoader,17+ Route as OwnerRoute,18+} from "../src/routes/$owner/index.tsx";19+import { Route as ImportRoute } from "../src/routes/import.tsx";20+21+/** What the loader's load came to for `owner`: a redirect, a 404, or neither. */22+interface Outcome {23+ readonly location?: string | null;24+ readonly notFound: boolean;25+ readonly status?: number;26+}27+28+/** What the route's loader rejects with for `owner`, as an outcome. */29+const outcomeFor = (owner: string) =>30+ Effect.tryPromise({31+ catch: (thrown): Outcome =>32+ isRedirect(thrown)33+ ? {34+ location: thrown.headers.get("location"),35+ notFound: false,36+ status: thrown.status,37+ }38+ : { notFound: isNotFound(thrown) },39+ try: () => ownerLoader({ params: { owner } }),40+ }).pipe(Effect.flip);41+42+/** The route the app's own tree finds for `pathname`. */43+const routeAt = (pathname: string) => getRouter().getMatchedRoutes(pathname)[2];44+45+describe("an owner's address alone", () => {46+ it.effect(47+ "is a 302 to the person's page, in lowercase, when it names a handle",48+ () =>49+ Effect.gen(function* () {50+ const toPerson = {51+ location: "/people/oscabriel",52+ notFound: false,53+ status: 302,54+ };55+56+ expect(yield* outcomeFor("oscabriel")).toStrictEqual(toPerson);57+ expect(yield* outcomeFor("OscaBriel")).toStrictEqual(toPerson);58+ })59+ );60+61+ it.effect.each(["github.com", "gitlab.com", "not_a.handle"])(62+ "%s is not found",63+ (owner) =>64+ Effect.gen(function* () {65+ expect(yield* outcomeFor(owner)).toStrictEqual({ notFound: true });66+ })67+ );68+69+ it.effect(70+ "is not found for every word the web keeps, never a person's page",71+ () =>72+ Effect.gen(function* () {73+ const outcomes = yield* Effect.forEach(74+ [...reservedProjectNames, "Icons"],75+ outcomeFor76+ );77+78+ expect(outcomes.filter(({ notFound }) => !notFound)).toStrictEqual([]);79+ })80+ );81+});82+83+describe("the app's router", () => {84+ it("reaches the owner's route for /<handle>, and its own page for /import", () => {85+ expect(routeAt("/oscabriel")).toBe(OwnerRoute);86+ expect(routeAt("/import")).toBe(ImportRoute);87+ });88+});modified:apps/web/test/shell.test.tsx+73 added
23 unmodified lines24 import { AppLink } from "../src/features/shared/link.tsx";25 import { projectPath } from "../src/features/shared/paths.ts";26 import { RouteError } from "../src/features/shared/pending.tsx";27 import { AppShell } from "../src/features/shared/shell/app-shell.tsx";28+import { ShellReadsContext } from "../src/features/shared/shell/context.ts";29+import { ProjectsSheetBody } from "../src/features/shared/shell/overlays.tsx";30 import { RailSlot } from "../src/features/shared/shell/rail-slot.tsx";31 import { Workspace } from "../src/features/shared/shell/workspace.tsx";32+import { EIGHT_LEADING, TEN_LISTED } from "./listings.ts";33 import { renderAt } from "./render.tsx";34 35 /** The element `tag` whose opening tag carries `attribute`, whole (no nested `tag`). */36 const elementOf = (markup: string, tag: string, attribute: string) =>337 unmodified lines374 </p>375 );376 };377 378+/** The projects named in `markup`'s rail rows, in order. */379+const railProjectsOf = (markup: string) =>380+ [381+ ...elementOf(markup, "nav", 'aria-label="Site"').matchAll(382+ /<a\b[^>]*data-project="(?<project>[^"]+)"/gu383+ ),384+ ].map(({ groups }) => groups?.project);385+386+/** The ledger page at `url`, its rail fed the ten listed projects. */387+const listedAt = (url: string) =>388+ renderAt(389+ url,390+ <AppShell projects={TEN_LISTED}>391+ <Workspace title="Ledger">392+ <p>Entries</p>393+ </Workspace>394+ </AppShell>395+ );396+397+describe("the rail's projects", () => {398+ it.effect(399+ "are eight, the most open asks first and a tie by name, each by its full name",400+ () =>401+ Effect.gen(function* () {402+ expect(railProjectsOf(yield* listedAt("/agents"))).toStrictEqual(403+ EIGHT_LEADING404+ );405+ })406+ );407+408+ it.effect(409+ "pin the current project first, then the seven that lead among the others",410+ () =>411+ Effect.gen(function* () {412+ expect(413+ railProjectsOf(yield* listedAt("/oscabriel/yarrow/ledger"))414+ ).toStrictEqual(["oscabriel/yarrow", ...EIGHT_LEADING.slice(0, 7)]);415+ expect(416+ railProjectsOf(yield* listedAt("/oscabriel/datekit/ledger"))417+ ).toStrictEqual([418+ "oscabriel/datekit",419+ ...EIGHT_LEADING.filter((name) => name !== "oscabriel/datekit"),420+ ]);421+ })422+ );423+});424+425+describe("the project switcher", () => {426+ it.effect(427+ "lists every project by its full name, and ends with the way to import a repo",428+ () =>429+ Effect.gen(function* () {430+ const markup = yield* renderAt(431+ "/agents",432+ <ShellReadsContext value={{ projects: TEN_LISTED }}>433+ <ProjectsSheetBody input={{ current: null }} onChosen={() => {}} />434+ </ShellReadsContext>435+ );436+437+ expect(438+ TEN_LISTED.filter(({ project }) => !markup.includes(`>${project}<`))439+ ).toStrictEqual([]);440+ expect(linksOf(markup).at(-1)).toMatchObject({441+ href: "/import",442+ text: "Import a repo",443+ });444+ })445+ );446+});447+448 describe("a project at its source path", () => {449 it.effect(450 "reaches the project's pages with its owner in one param, and links back to the same address",451 () =>159 unmodified lines