Lead the rail and the landing with the projects that have the most open asks, by full name, and send /<handle> to the person's page
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by oscabriel · committed by oscabriel · parent 059c75c · Browse files · 9 files·+280 added−46 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+280 added−46 removed
- tests:+185 added−26 removed
- other:+95 added−20 removed
Provenance
- Commit
b949fcc- Tree
faf580e- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
059c75c
9 files changed+280 added−46 removed
modified:apps/web/src/features/landing/projects.ts+8 added-5 removed
1232345678910111213111415161718192021192223242526242728/** * 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";
import { leadingProjects } from "../shared/project-order.ts";
/** The projects the page names; the rest are a step away, at `/asks`. */export const PROJECTS_SHOWN = 8;
/** 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+25 added-12 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+140-/** The phone's More: Docs, For agents, the project's sections, the keys, the session. */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();167 const { open } = useShell();117 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+6 added-3 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 } from "../project-order.ts";43 import {44 useCurrentProject,45 useProjectList,46 useShell,174 unmodified lines221 );222 223 /**224 * 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.225+ * arriving after the page moves nothing above it; then the others that226+ * lead (the most open asks first, a tie by name), up to eight in all, and227+ * the switcher for the rest.228 */229 const Projects = () => {230 const current = useCurrentProject();231 const listed = useProjectList();3 unmodified lines235 listed?.find((listing) => listing.project === project);236 237 const others = (listed ?? []).filter(({ project }) => project !== current);238 const room = SHOWN - (current === undefined ? 0 : 1);239+ const leading = leadingProjects(others, room);240 241 return (242 <div className="flex flex-col gap-1">243 <h2 className="text-label text-muted-foreground px-2 pt-4 pb-1">15 unmodified lines259 )}260 {listed === undefined ? (261 <PlaceholderRows />262 ) : (260- others.slice(0, room).map((listing) => (263+ leading.map((listing) => (264 <li key={listing.project}>265 <ProjectRow266 current={false}267 listing={listing}154 unmodified linesadded:apps/web/src/features/shared/project-order.ts+23 added
1234567891011121314151617181920212223/** * 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";
/** 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+33 added
123456789101112131415161718192021222324252627282930313233import { Handle } from "@repo/protocol/ids";import { createFileRoute, notFound, redirect } from "@tanstack/react-router";import { Effect, Schema } from "effect";
// `/<owner>` alone: a handle leads to the person's page,// `/people/<handle>`, 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`) is// not found.
/** The redirect to the person's page, or a 404, as the route's loader rejects. */export const ownerLoader = ({ params,}: { readonly params: { readonly owner: string };}) => Effect.runPromise( Schema.decodeEffect(Handle)(params.owner).pipe( Effect.mapError(() => notFound()), Effect.flatMap((handle) => Effect.fail( redirect({ params: { handle }, statusCode: 302, to: "/people/$handle", }) ) ) ) );
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+64 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364/** * An owner's address alone: `/<handle>` leads to the person's * page, `/people/<handle>`, by a 302 (a handle may yet become a page of its * own); an owner that is no handle, a source host among them, is not * found. The route's own loader is run inside a router in memory, as the * server runs it. */import { describe, expect, it } from "@effect/vitest";import { createMemoryHistory, createRootRoute, createRoute, createRouter,} from "@tanstack/react-router";import { Effect } from "effect";
import { ownerLoader } from "../src/routes/$owner/index.tsx";
/** The router at `url`, its tree the owner's route and the person's page. */const loadedAt = (url: string) => { const root = createRootRoute();
const router = createRouter({ history: createMemoryHistory({ initialEntries: [url] }), routeTree: root.addChildren([ createRoute({ getParentRoute: () => root, path: "people/$handle" }), createRoute({ getParentRoute: () => root, loader: ownerLoader, path: "$owner", }), ]), });
// What the server's load chose, which Start answers the request with: a // redirect, or a render at its status. return Effect.map( Effect.promise(() => router.load()), () => router._serverResult );};
describe("an owner's address alone", () => { it.effect("is a 302 to the person's page when it names a handle", () => Effect.gen(function* () { const result = yield* loadedAt("/oscabriel"); const redirect = result?.type === "redirect" ? result.redirect : null;
expect(redirect?.status).toBe(302); expect(redirect?.headers.get("location")).toBe("/people/oscabriel"); }) );
it.effect.each(["/github.com", "/gitlab.com", "/not_a.handle"])( "%s is not found", (path) => Effect.gen(function* () { expect(yield* loadedAt(path)).toMatchObject({ status: 404, type: "render", }); }) );});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