Skip to content
Source
Sign inSign up

review.ts

31 lines1.2 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 registry.set(
27 lastReviewGitSectionsAtom(target.environmentId, target.input.cwd),
28 value.sources,
29 ),
30 ),
31});