Lead /<Handle> to the person's page in lowercase, keep the web's words not found, and name the eight once
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by oscabriel · committed by oscabriel · parent b949fcc · Browse files · 6 files·+105 added−74 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+105 added−74 removed
- tests:+70 added−46 removed
- other:+35 added−28 removed
Provenance
- Commit
2bb32e1- Tree
b4449eb- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
b949fcc
6 files changed+105 added−74 removed
modified:apps/web/src/features/landing/projects.ts+1 added-4 removed
4 unmodified lines567899101112131112131411 unmodified lines4 unmodified lines */import { ProjectListing } from "@repo/protocol/domain/front-page";import { Schema } from "effect";
import { leadingProjects } from "../shared/project-order.ts";import { leadingProjects, PROJECTS_SHOWN } 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 ones that lead, or that the list did not come. */export const LandingProjects = Schema.TaggedUnion({ Listed: { projects: Schema.Array(ProjectListing) }, Unreachable: {},11 unmodified linesmodified:apps/web/src/features/shared/shell/overlays.tsx+1 added-1 removed
158 unmodified lines159 </div>160 </>161 );162 163-/** 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();130 unmodified linesmodified:apps/web/src/features/shared/shell/rail.tsx+2 added-5 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";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 62-/** At most this many projects in the rail; more open the switcher. */63-const SHOWN = 8;64-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" },165 unmodified lines231 const listingOf = (project: string) =>232 listed?.find((listing) => listing.project === project);233 234 const others = (listed ?? []).filter(({ project }) => project !== current);238- 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">179 unmodified linesmodified:apps/web/src/features/shared/project-order.ts+3 added
5 unmodified lines67891011121314151610 unmodified lines5 unmodified lines */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),10 unmodified linesmodified:apps/web/src/routes/$owner/index.tsx+28 added-18 removed
112334567678891011121013141516171819202122232425261527281718192021222324252627293031323334353637383940412 unmodified linesimport { Handle } from "@repo/protocol/ids";import { Handle, reservedProjectNames } from "@repo/protocol/ids";import { createFileRoute, notFound, redirect } from "@tanstack/react-router";import { Effect, Schema } from "effect";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>`, 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.// `/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.
/** The redirect to the person's page, or a 404, as the route's loader rejects. */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( Schema.decodeEffect(Handle)(params.owner).pipe( Effect.mapError(() => notFound()), Effect.flatMap((handle) => Effect.fail( redirect({ params: { handle }, statusCode: 302, to: "/people/$handle", }) ) ) 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/")({2 unmodified linesmodified:apps/web/test/owner-route.test.ts+70 added-46 removed
1234562345678991011121314101112131714151617181920192021212223242526272324252627282930313233282930313233343536373839404135363738394041424344454445464746474849505152535455495051565758596054616256636458596061656667686970717273747576777879808182838485868788/** * 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. * An owner's address alone: `/<handle>` leads to the person's page, * `/people/<handle>` in lowercase (handles compare without case), by a 302 * (a handle may yet become a page of its own); an owner that is no handle, * a source host among them, and a word the web keeps for itself are not * found. The app's own router reaches the route for `/<handle>` and still * reaches its own pages by their words. */import { describe, expect, it } from "@effect/vitest";import { createMemoryHistory, createRootRoute, createRoute, createRouter,} from "@tanstack/react-router";import { reservedProjectNames } from "@repo/protocol/ids";import { isNotFound, isRedirect } from "@tanstack/react-router";import { Effect } from "effect";
import { ownerLoader } from "../src/routes/$owner/index.tsx";import { getRouter } from "../src/router.tsx";import { ownerLoader, Route as OwnerRoute,} from "../src/routes/$owner/index.tsx";import { Route as ImportRoute } from "../src/routes/import.tsx";
/** The router at `url`, its tree the owner's route and the person's page. */const loadedAt = (url: string) => { const root = createRootRoute();/** What the loader's load came to for `owner`: a redirect, a 404, or neither. */interface Outcome { readonly location?: string | null; readonly notFound: boolean; readonly status?: number;}
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 route's loader rejects with for `owner`, as an outcome. */const outcomeFor = (owner: string) => Effect.tryPromise({ catch: (thrown): Outcome => isRedirect(thrown) ? { location: thrown.headers.get("location"), notFound: false, status: thrown.status, } : { notFound: isNotFound(thrown) }, try: () => ownerLoader({ params: { owner } }), }).pipe(Effect.flip);
// 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 );};/** The route the app's own tree finds for `pathname`. */const routeAt = (pathname: string) => getRouter().getMatchedRoutes(pathname)[2];
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; it.effect( "is a 302 to the person's page, in lowercase, when it names a handle", () => Effect.gen(function* () { const toPerson = { location: "/people/oscabriel", notFound: false, status: 302, };
expect(redirect?.status).toBe(302); expect(redirect?.headers.get("location")).toBe("/people/oscabriel"); }) expect(yield* outcomeFor("oscabriel")).toStrictEqual(toPerson); expect(yield* outcomeFor("OscaBriel")).toStrictEqual(toPerson); }) );
it.effect.each(["/github.com", "/gitlab.com", "/not_a.handle"])( it.effect.each(["github.com", "gitlab.com", "not_a.handle"])( "%s is not found", (path) => (owner) => Effect.gen(function* () { expect(yield* loadedAt(path)).toMatchObject({ status: 404, type: "render", }); expect(yield* outcomeFor(owner)).toStrictEqual({ notFound: true }); }) );
it.effect( "is not found for every word the web keeps, never a person's page", () => Effect.gen(function* () { const outcomes = yield* Effect.forEach( [...reservedProjectNames, "Icons"], outcomeFor );
expect(outcomes.filter(({ notFound }) => !notFound)).toStrictEqual([]); }) );});
describe("the app's router", () => { it("reaches the owner's route for /<handle>, and its own page for /import", () => { expect(routeAt("/oscabriel")).toBe(OwnerRoute); expect(routeAt("/import")).toBe(ImportRoute); });});