Skip to content
Myr

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 file

Take it

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 1–13why, one step back
1import { 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 back
14import { signInHref } from "../auth/session-slot.tsx";

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

line 15why, one step back
15import { CommandLine } from "../shared/command.tsx";

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 16–18why, one step back
16import { 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 back
19
20export 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 back
29 * `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 back
31 */
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 });60

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 61–77why, one step back
61const 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>"`;77

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 78–86why, one step back
78const 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 back
87 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 back
88 >

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 89–91why, one step back
89 <p className="text-body">
90 A proposal asks {project} to open an ask nobody wrote yet: a want in your91 words, which the platform&apos;s agent can draft into an ask file and a

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

line 92why, one step back
92 failing check for a maintainer to accept.

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 93–99why, one step back
93 </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 back
100 <span>

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 101why, one step back
101 Proposing is for signed-in members.{" "}

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 102–103why, one step back
102 <a
103 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 back
104 href={signInHref(proposeFormPath(project, about))}

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 105–107why, one step back
105 >
106 Sign in107 </a>{" "}

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 108why, one step back
108 to propose one here, or propose from your clone:

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 109–110why, one step back
109 </span>
110 </p>

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 111why, one step back
111 <CommandLine command={PROPOSE_COMMAND} />

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 112–114why, one step back
112 </section>
113);114

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 115–130why, one step back
115const 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 back
131 about,

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 132why, one step back
132 busy,

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 133–140why, one step back
133 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 back
141 readonly onPropose?: ((payload: ProposePayload) => void) | undefined;
142 readonly busy: boolean;

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

line 143why, one step back
143 readonly children?: ReactNode;

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 144why, one step back
144}) => {

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 145–150why, one step back
145 const id = useId();
146147 const [want, setWant] = useState(() =>148 Option.match(about, { onNone: () => "", onSome: wantAbout })149 );150

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 151why, one step back
151 const [territory, setTerritory] = useState(AGENT_CHOOSES);

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 152–154why, one step back
152 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 back
155 const choices = territoryChoices(modules);

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 156–159why, one step back
156
157 return (158 <form159 aria-label="Propose an ask"

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 160why, one step back
160 className="flex max-w-(--measure) flex-col gap-6"

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 161why, one step back
161 data-propose=""

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 162–176why, one step back
162 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 back
177 <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 back
179 </label>
180 <Textarea

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 181why, one step back
181 className="min-h-32 text-base leading-6"

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 182–192why, one step back
182 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 back
193 <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 back
200 value={territory}

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 201–205why, one step back
201 />
202 <p className="text-label text-muted-foreground font-normal">203 One of the project&apos;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 back
206 </div>
207

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 208–224why, one step back
208 <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&apos;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 red

Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571

lines 225–226why, one step back
225 first, and puts the draft to a maintainer. Clear the box to propose
226 the want alone.

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 227why, one step back
227 </p>

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 228–232why, one step back
228 </div>
229230 {children}231232 <Button

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 233–234why, one step back
233 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 back
235 disabled={busy || !written}
236 type="submit"

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 237why, one step back
237 variant={written ? "default" : "outline"}

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 238–239why, one step back
238 >
239 {busy ? <Spinner /> : null}

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

line 240why, one step back
240 {proposeWords(written, busy)}

Merge branch 'build/911-web-propose-and-proposal'oscabrielbefore adoptionbcb4cd9

lines 241–244why, one step back
241 </Button>
242 </form>243 );244};

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 245–314why, one step back
245
246const 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 back
315 meta="A maintainer decides whether the ask opens; nothing lands from here."

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 316–328why, one step back
316 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 back
329 <div className="border-rule flex flex-col border-t pt-4">

Merge build/1224-decider-pagesoscabrielbefore adoptiond22b7a2

lines 330–334why, one step back
330 <GoodWant />
331 </div>332 </Workspace>333 </div>334);