propose-view.tsx
This file
Path
apps/web/src/features/propose/propose-view.tsx
334 lines · 9.3 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 1–13why, one step back1import { Brand } from "@repo/brand";2import type { ProposeAsk } from "@repo/protocol/contracts";3import type { CommitSha, ProjectName, RepoPath } from "@repo/protocol/ids";4import { Option } from "effect";5import { LogIn } from "lucide-react";6import { useId, useState } from "react";7import type { ReactNode } from "react";89import { Button } from "../../components/ui/button.tsx";10import { Checkbox } from "../../components/ui/checkbox.tsx";11import { Label } from "../../components/ui/label.tsx";12import { Spinner } from "../../components/ui/spinner.tsx";13import { Textarea } from "../../components/ui/textarea.tsx";Close the wave: openings are heard as landings, and the code store is written downoscabrielbefore adoption2587726
line 14why, one step back14import { signInHref } from "../auth/session-slot.tsx";Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
line 15why, one step back15import { CommandLine } from "../shared/command.tsx";Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 16–18why, one step back16import { FactBlock } from "../shared/facts.tsx";17import { Workspace } from "../shared/shell/workspace.tsx";18import { ClientTerritorySelect } from "./client-territory.tsx";Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 19–28why, one step back1920export type ProposePayload = typeof ProposeAsk.payloadSchema.Type;2122export interface About {23 readonly path: RepoPath;24 readonly line: number;25 readonly at: CommitSha;26}2728/**Merge build/comments-web-features into mainoscabrielbefore adoption74bfc72
lines 29–30why, one step back29 * `draft: true` only when the box is checked: the contract takes no `draft:30 * false`.Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 31–60why, one step back31 */32export const proposalPayload = (form: {33 readonly project: ProjectName;34 readonly want: string;35 readonly territory?: RepoPath;36 readonly draft: boolean;37}): ProposePayload => {38 const want = form.want.trim();3940 const named =41 form.territory === undefined42 ? { project: form.project, want }43 : { project: form.project, territory: form.territory, want };4445 return form.draft ? { ...named, draft: true } : named;46};4748export const wantAbout = ({ at, line, path }: About) =>49 `In \`${path}\` line ${line} at ${at.slice(0, 7)}: `;5051export const proposeFormPath = (52 project: ProjectName,53 about: Option.Option<About> = Option.none()54) =>55 Option.match(about, {56 onNone: () => `/${project}/proposals/new`,57 onSome: ({ at, line, path }) =>58 `/${project}/proposals/new?${new URLSearchParams({ about: path, at, line: String(line) }).toString()}`,59 });60Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 61–77why, one step back61const AGENT_CHOOSES = "";6263export const territoryChoices = (modules: readonly RepoPath[]) => [64 { label: "Let the agent choose", value: AGENT_CHOOSES },65 ...modules.map((module) => ({ label: module, value: module })),66];6768const proposeWords = (written: boolean, busy: boolean) => {69 if (!written) {70 return "Write the want first";71 }7273 return busy ? "Proposing" : "Propose";74};7576const PROPOSE_COMMAND = `${Brand.cli} propose --draft "<want>"`;77Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 78–86why, one step back78const SignInFirst = ({79 about,80 project,81}: {82 readonly about: Option.Option<About>;83 readonly project: ProjectName;84}) => (85 <section86 aria-label="Sign in to propose"Merge redesign into mainoscabrielbefore adoptioncaedd21
line 87why, one step back87 className="flex max-w-(--measure) flex-col items-start gap-3"Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
line 88why, one step back88 >Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 89–91why, one step back89 <p className="text-body">90 A proposal asks {project} to open an ask nobody wrote yet: a want in your91 words, which the platform's agent can draft into an ask file and aMerge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 92why, one step back92 failing check for a maintainer to accept.Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 93–99why, one step back93 </p>94 <p className="text-ui flex items-start gap-2">95 <LogIn96 aria-hidden="true"97 className="mt-0.5 size-4 shrink-0"98 strokeWidth={1.75}99 />Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
line 100why, one step back100 <span>Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
line 101why, one step back101 Proposing is for signed-in members.{" "}Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 102–103why, one step back102 <a103 className="decoration-rule font-medium underline hover:decoration-current"Close the wave: openings are heard as landings, and the code store is written downoscabrielbefore adoption2587726
line 104why, one step back104 href={signInHref(proposeFormPath(project, about))}Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 105–107why, one step back105 >106 Sign in107 </a>{" "}Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
line 108why, one step back108 to propose one here, or propose from your clone:Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 109–110why, one step back109 </span>110 </p>Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
line 111why, one step back111 <CommandLine command={PROPOSE_COMMAND} />Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 112–114why, one step back112 </section>113);114Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 115–130why, one step back115const GoodWant = () => (116 <>117 <FactBlock label="A good want">118 <ul className="text-ui flex list-disc flex-col gap-1.5 pl-4">119 <li>Says what the project should do, not how to change the code.</li>120 <li>Asks for one change, small enough to check on its own.</li>121 <li>Says how you would tell it is done: what a check would see.</li>122 </ul>123 </FactBlock>124 <FactBlock label="From a terminal">125 <CommandLine command={PROPOSE_COMMAND} numbered />126 </FactBlock>127 </>128);129130const Form = ({Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
line 131why, one step back131 about,Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
line 132why, one step back132 busy,Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 133–140why, one step back133 children,134 modules,135 onPropose,136 project,137}: {138 readonly project: ProjectName;139 readonly about: Option.Option<About>;140 readonly modules: readonly RepoPath[];Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 141–142why, one step back141 readonly onPropose?: ((payload: ProposePayload) => void) | undefined;142 readonly busy: boolean;Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
line 143why, one step back143 readonly children?: ReactNode;Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
line 144why, one step back144}) => {Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 145–150why, one step back145 const id = useId();146147 const [want, setWant] = useState(() =>148 Option.match(about, { onNone: () => "", onSome: wantAbout })149 );150Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
line 151why, one step back151 const [territory, setTerritory] = useState(AGENT_CHOOSES);Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 152–154why, one step back152 const [draft, setDraft] = useState(true);153 const chosen = modules.find((module) => module === territory);154 const written = want.trim().length > 0;Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
line 155why, one step back155 const choices = territoryChoices(modules);Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 156–159why, one step back156157 return (158 <form159 aria-label="Propose an ask"Merge redesign into mainoscabrielbefore adoptioncaedd21
line 160why, one step back160 className="flex max-w-(--measure) flex-col gap-6"Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
line 161why, one step back161 data-propose=""Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 162–176why, one step back162 onSubmit={(event) => {163 event.preventDefault();164165 if (written) {166 onPropose?.(167 proposalPayload(168 chosen === undefined169 ? { draft, project, want }170 : { draft, project, territory: chosen, want }171 )172 );173 }174 }}175 >176 <div className="flex flex-col gap-1.5">Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 177–178why, one step back177 <label className="text-ui font-medium" htmlFor={`${id}-want`}>178 What should {project} do that it does not do now?Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 179–180why, one step back179 </label>180 <TextareaMerge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
line 181why, one step back181 className="min-h-32 text-base leading-6"Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 182–192why, one step back182 id={`${id}-want`}183 name="want"184 onChange={(event) => {185 setWant(event.target.value);186 }}187 required188 value={want}189 />190 </div>191192 <div className="flex flex-col gap-1.5">Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 193–199why, one step back193 <span className="text-ui font-medium" id={`${id}-territory`}>194 Territory195 </span>196 <ClientTerritorySelect197 choices={choices}198 labelledBy={`${id}-territory`}199 onChange={setTerritory}Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
line 200why, one step back200 value={territory}Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 201–205why, one step back201 />202 <p className="text-label text-muted-foreground font-normal">203 One of the project's top folders, or the agent picks from the204 want.205 </p>Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 206–207why, one step back206 </div>207Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 208–224why, one step back208 <div className="flex flex-col gap-1.5">209 <div className="flex items-start gap-2">210 <Checkbox211 checked={draft}212 className="mt-0.5"213 id={`${id}-draft`}214 name="draft"215 onCheckedChange={(checked) => {216 setDraft(checked);217 }}218 />219 <Label className="text-ui leading-snug" htmlFor={`${id}-draft`}>220 Let the platform's agent draft the ask221 </Label>222 </div>223 <p className="text-label text-muted-foreground pl-6 font-normal">224 It writes the ask file and a check that fails on main, runs it redMerge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
lines 225–226why, one step back225 first, and puts the draft to a maintainer. Clear the box to propose226 the want alone.Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
line 227why, one step back227 </p>Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 228–232why, one step back228 </div>229230 {children}231232 <ButtonMerge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 233–234why, one step back233 className={`tablet:h-9 tablet:w-fit h-11 w-full min-w-28 px-4 ${written ? "" : "text-muted-foreground border-dashed disabled:opacity-100"}`}234 data-written={written}Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 235–236why, one step back235 disabled={busy || !written}236 type="submit"Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
line 237why, one step back237 variant={written ? "default" : "outline"}Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 238–239why, one step back238 >239 {busy ? <Spinner /> : null}Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
line 240why, one step back240 {proposeWords(written, busy)}Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9
lines 241–244why, one step back241 </Button>242 </form>243 );244};Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 245–314why, one step back245246const ProposeBody = ({247 about,248 busy,249 checking,250 children,251 modules,252 onPropose,253 project,254 signedIn,255}: {256 readonly project: ProjectName;257 readonly signedIn: boolean;258 readonly checking: boolean;259 readonly about: Option.Option<About>;260 readonly modules: readonly RepoPath[];261 readonly onPropose?: ((payload: ProposePayload) => void) | undefined;262 readonly busy: boolean;263 readonly children?: ReactNode;264}) => {265 if (checking) {266 return (267 <output className="text-ui text-muted-foreground block">268 Checking who is signed in269 </output>270 );271 }272273 return signedIn ? (274 <Form275 about={about}276 busy={busy}277 modules={modules}278 onPropose={onPropose}279 project={project}280 >281 {children}282 </Form>283 ) : (284 <SignInFirst about={about} project={project} />285 );286};287288export const ProposeView = ({289 about,290 busy = false,291 checking = false,292 children,293 modules,294 onPropose,295 project,296 signedIn,297}: {298 readonly project: ProjectName;299 readonly signedIn: boolean;300 readonly checking?: boolean;301 readonly about: Option.Option<About>;302 readonly modules: readonly RepoPath[];303 readonly onPropose?: (payload: ProposePayload) => void;304 readonly busy?: boolean;305 readonly children?: ReactNode;306}): ReactNode => (307 <div className="contents [&_[data-facts=inline]]:hidden">308 <Workspace309 crumbs={[310 { label: project, to: `/${project}` },311 { label: "Propose an ask" },312 ]}313 facts={<GoodWant />}314 factsHeading="Proposing"Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 315why, one step back315 meta="A maintainer decides whether the ask opens; nothing lands from here."Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 316–328why, one step back316 title="Propose an ask"317 >318 <ProposeBody319 about={about}320 busy={busy}321 checking={checking}322 modules={modules}323 onPropose={onPropose}324 project={project}325 signedIn={signedIn}326 >327 {children}328 </ProposeBody>Merge redesign into mainoscabrielbefore adoptioncaedd21
line 329why, one step back329 <div className="border-rule flex flex-col border-t pt-4">Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2
lines 330–334why, one step back330 <GoodWant />331 </div>332 </Workspace>333 </div>334);