Skip to content
Myr

explore-page.tsx

This file

Path

apps/web/src/features/explore/explore-page.tsx

181 lines · 5.5 KiB · TypeScript

Last changed by

Merge redesign into mainoscabrielbefore adoptioncaedd21

History of this file

Take it

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 1–181why, one step back
1import type { ProjectListing } from "@repo/protocol/domain/front-page";
2import { ownerOf, shortNameOf } from "@repo/protocol/ids";3import { DateTime } from "effect";4import type { ReactNode } from "react";56import { LandingProjects } from "../landing/projects.ts";7import { postureLabel } from "../project/posture-label.ts";8import { EmptyState } from "../shared/empty.tsx";9import { AppLink } from "../shared/link.tsx";10import { ASKS_PATH, projectPath } from "../shared/paths.ts";11import { UnreachableNotice } from "../shared/pending.tsx";12import { PostureBadge } from "../shared/posture.tsx";13import { GUTTER } from "../shared/shell/gutter.ts";14import { exploreGroups } from "./groups.ts";15import { EXPLORE_LEDE, EXPLORE_TITLE } from "./words.ts";1617const plural = (count: number, one: string, many: string) =>18 `${count} ${count === 1 ? one : many}`;1920// A day, never a span: the page is kept at the edge, where "5 min ago" would go stale.21const dayOf = (at: DateTime.Utc) =>22 DateTime.formatUtc(at, {23 day: "numeric",24 locale: "en-US",25 month: "short",26 year: "numeric",27 });2829const LastLanded = ({ at }: { readonly at: DateTime.Utc | undefined }) =>30 at === undefined ? (31 <span>No landing yet</span>32 ) : (33 <span>34 Last landed <time dateTime={DateTime.formatIso(at)}>{dayOf(at)}</time>35 </span>36 );3738/** A plain bordered surface: the name, its posture, one line, then its counts. */39const ProjectCard = ({40 listing: { description, landedAt, landings, openAsks, posture, project },41}: {42 readonly listing: ProjectListing;43}) => (44 <li45 className="border-rule bg-card flex min-w-0 flex-col gap-3 rounded-md border p-4"46 data-project={project}47 >48 <div className="flex flex-wrap items-start justify-between gap-x-4 gap-y-1">49 <AppLink50 className="text-want min-w-0 [overflow-wrap:anywhere] no-underline hover:underline"51 to={projectPath(project)}52 >53 <span className="text-muted-foreground">{ownerOf(project)}/</span>54 <span className="font-semibold">{shortNameOf(project)}</span>55 </AppLink>56 <PostureBadge label={postureLabel(posture)} posture={posture} />57 </div>58 {description === undefined ? null : (59 <p className="text-ui text-muted-foreground line-clamp-2 flex-1">60 {description}61 </p>62 )}63 <p className="text-ui text-muted-foreground border-rule mt-auto flex flex-wrap gap-x-4 gap-y-1 border-t pt-3">64 <span className={openAsks > 0 ? "text-foreground font-medium" : ""}>65 {openAsks > 066 ? plural(openAsks, "open ask", "open asks")67 : "No open asks"}68 </span>69 {landings === undefined ? null : (70 <span>{plural(landings, "landing", "landings")}</span>71 )}72 <LastLanded at={landedAt} />73 </p>74 </li>75);7677const CardGrid = ({78 projects,79}: {80 readonly projects: readonly ProjectListing[];81}) => (82 <ul className="tablet:grid-cols-2 columns:grid-cols-3 grid grid-cols-1 gap-4">83 {projects.map((listing) => (84 <ProjectCard key={listing.project} listing={listing} />85 ))}86 </ul>87);8889const Group = ({90 children,91 group,92 heading,93 note,94}: {95 readonly children: ReactNode;96 readonly group: "rest" | "taking";97 readonly heading: string;98 readonly note: string;99}) => (100 <section101 aria-labelledby={`explore-${group}`}102 className="flex flex-col gap-4"103 data-group={group}104 >105 <div className="flex flex-col gap-1">106 <h2 className="text-title" id={`explore-${group}`}>107 {heading}108 </h2>109 <p className="text-ui text-muted-foreground">{note}</p>110 </div>111 {children}112 </section>113);114115const Listed = ({116 projects,117}: {118 readonly projects: readonly ProjectListing[];119}) => {120 const { rest, taking } = exploreGroups(projects);121122 return (123 <>124 <Group125 group="taking"126 heading="Taking answers now"127 note="Projects with asks open to claim."128 >129 {taking.length === 0 ? (130 <EmptyState title="No project has an open ask right now." />131 ) : (132 <CardGrid projects={taking} />133 )}134 </Group>135 {rest.length === 0 ? null : (136 <Group137 group="rest"138 heading="Other projects"139 note="Projects with no open ask, to read and to watch."140 >141 <CardGrid projects={rest} />142 </Group>143 )}144 </>145 );146};147148const Lede = ({ projects }: { readonly projects: LandingProjects }) =>149 LandingProjects.match(projects, {150 Listed: ({ projects: listed }) =>151 `${plural(listed.length, "public project", "public projects")}, the ones taking answers first.`,152 Unreachable: () => EXPLORE_LEDE,153 });154155const Body = ({ projects }: { readonly projects: LandingProjects }) =>156 LandingProjects.match(projects, {157 Listed: ({ projects: listed }) => <Listed projects={listed} />,158 Unreachable: () => <UnreachableNotice />,159 });160161/** The public projects as cards, in two groups, or a notice when the platform did not answer. */162export const ExploreView = ({163 projects,164}: {165 readonly projects: LandingProjects;166}) => (167 <main168 className={`flex flex-1 flex-col gap-12 pt-6 pb-16 outline-none ${GUTTER}`}169 id="main"170 tabIndex={-1}171 >172 <div className="flex flex-col gap-3">173 <h1 className="text-headline">{EXPLORE_TITLE}</h1>174 <p className="text-body text-muted-foreground max-w-(--measure)">175 <Lede projects={projects} /> Looking for something to work on?{" "}176 <AppLink to={ASKS_PATH}>See every open ask</AppLink>.177 </p>178 </div>179 <Body projects={projects} />180 </main>181);