Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

review.ts

38 lines1.5 KB

1import { createReviewEnvironmentAtoms } from "@t3tools/client-runtime/state/review";
2import type { EnvironmentId, ReviewDiffPreviewSource } from "@t3tools/contracts";
3import * as Effect from "effect/Effect";
4import { Atom } from "effect/reactivity";
5​
6import { connectionAtomRuntime } from "../connection/runtime";
7​
8const EMPTY_GIT_SECTIONS = Object.freeze<ReadonlyArray<ReviewDiffPreviewSource>>([]);
9​
10// The last answered preview per worktree, so review keeps showing git sections while the live
11// query is not mounted. useReviewSections still hides them unless the session grants file reads.
12const lastGitSectionsFamily = Atom.family((key: string) =>
13 Atom.make(EMPTY_GIT_SECTIONS).pipe(
14 Atom.keepAlive,
15 Atom.withLabel(`mobile:review:git-sections:${key}`),
16 ),
17);
18​
19export function lastReviewGitSectionsAtom(environmentId: EnvironmentId, cwd: string) {
20 return lastGitSectionsFamily(JSON.stringify([environmentId, cwd]));
22​
23export const reviewEnvironment = createReviewEnvironmentAtoms(connectionAtomRuntime, {
24 onDiffPreviewAnswer: (target, value, registry) =>
25 Effect.sync(() => {
26 const atom = lastReviewGitSectionsAtom(target.environmentId, target.input.cwd);
27 const kind = target.input.sourceKind;
28 registry.set(
29 atom,
30 kind === undefined
31 ? value.sources
32 : [
33 ...registry.get(atom).filter((source) => source.kind !== kind),
34 ...value.sources.filter((source) => source.kind === kind),
35 ],
36 );
37 }),
38});