Skip to content
Myr

propose.ts

This file

Path

apps/web/src/client/propose.ts

57 lines · 1.9 KiB · TypeScript

Last changed by

Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248

History of this file

Take it

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

lines 1–38why, one step back
1import type { ProposeAsk } from "@repo/protocol/contracts";
2import { RepoPath } from "@repo/protocol/ids";3import type { ProjectName, ProposalId } from "@repo/protocol/ids";4import { Array, Effect, Option, Order, Schema } from "effect";5import { AsyncResult, Atom, Reactivity } from "effect/reactivity";67import { ContractsClient } from "../surfaces.ts";8import { keys } from "./keys.ts";910const decodePath = Schema.decodeUnknownOption(RepoPath);1112export const topFolders = (paths: readonly RepoPath[]): readonly RepoPath[] => {13 const folders = paths.flatMap((path): readonly RepoPath[] => {14 const slash = path.indexOf("/");1516 return slash <= 0 || path.startsWith(".")17 ? []18 : Option.toArray(decodePath(path.slice(0, slash)));19 });2021 return Array.sort(Array.dedupe(folders), Order.String);22};2324export const modulesAtom = Atom.family((project: ProjectName) =>25 Atom.withServerValueInitial(26 ContractsClient.runtime.factory.withReactivity(keys.code(project))(27 ContractsClient.runtime.atom(28 Effect.gen(function* () {29 const client = yield* ContractsClient;30 const { paths } = yield* client("listPaths", { at: "main", project });3132 return topFolders(paths);33 })34 )35 )36 )37);38

Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248

line 39why, one step back
39// While a later send is on its way, or was refused, the atom still holds an earlier proposal; that names none here.

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

lines 40–57why, one step back
40export const proposalMade = (
41 result: AsyncResult.AsyncResult<typeof ProposeAsk.successSchema.Type, unknown>42): Option.Option<ProposalId> =>43 AsyncResult.isSuccess(result) && !result.waiting44 ? Option.some(result.value.proposal.id)45 : Option.none();4647export const proposeAtom = ContractsClient.runtime.fn<48 typeof ProposeAsk.payloadSchema.Type49>()(50 Effect.fnUntraced(function* (input) {51 const client = yield* ContractsClient;5253 return yield* client("proposeAsk", input).pipe(54 Reactivity.mutation(keys.project(input.project))55 );56 })57);