Open History to see the last commit
1import {
2 createEnvironmentShellAtoms,
3 createEnvironmentShellSummaryAtom,
4 createEnvironmentSnapshotAtom,
5 createShellEnvironmentAtoms,
6 EMPTY_SHELL_STATE,
7 type EnvironmentShellState,
8} from "@t3tools/client-runtime/state/shell";
9import { useAtomValue } from "@effect/atom-react";
10import type { EnvironmentId } from "@t3tools/contracts";
11import * as Option from "effect/Option";
12import { Atom } from "effect/reactivity";
13
14import { environmentCatalog } from "../connection/catalog";
15import { connectionAtomRuntime } from "../connection/runtime";
16
17export const shellEnvironment = createShellEnvironmentAtoms(connectionAtomRuntime);
18export const environmentShell = createEnvironmentShellAtoms(connectionAtomRuntime);
19export const environmentSnapshotAtom = createEnvironmentSnapshotAtom(environmentShell.stateAtom);
20export const environmentShellSummaryAtom = createEnvironmentShellSummaryAtom({
21 catalogValueAtom: environmentCatalog.catalogValueAtom,
22 shellStateValueAtom: environmentShell.stateValueAtom,
23});
24
25const EMPTY_ENVIRONMENT_SHELL_STATE_ATOM = Atom.make<EnvironmentShellState>(EMPTY_SHELL_STATE);
26
27const shellStatus = (state: EnvironmentShellState) => state.status;
28const shellHasError = (state: EnvironmentShellState) => Option.isSome(state.error);
29
30export function useEnvironmentShellReadiness(environmentId: EnvironmentId | null) {
31 const atom =
32 environmentId === null
33 ? EMPTY_ENVIRONMENT_SHELL_STATE_ATOM
34 : environmentShell.stateValueAtom(environmentId);
35 return {
36 status: useAtomValue(atom, shellStatus),
37 hasError: useAtomValue(atom, shellHasError),
38 };
39}