Open History to see the last commit
1import { useAtomValue } from "@effect/atom-react";
2import type {
3 EnvironmentProject,
4 EnvironmentThreadShell,
5} from "@t3tools/client-runtime/state/shell";
6import type {
7 EnvironmentId,
8 ScopedProjectRef,
9 ScopedThreadRef,
10 ServerConfig,
11} from "@t3tools/contracts";
12import { Atom } from "effect/unstable/reactivity";
13
14import { environmentProjects } from "./projects";
15import { environmentServerConfigsAtom, serverEnvironment } from "./server";
16import { environmentThreadShells } from "./threads";
17
18const EMPTY_PROJECT_ATOM = Atom.make<EnvironmentProject | null>(null).pipe(
19 Atom.withLabel("mobile-project:empty"),
20);
21const EMPTY_THREAD_SHELL_ATOM = Atom.make<EnvironmentThreadShell | null>(null).pipe(
22 Atom.withLabel("mobile-thread-shell:empty"),
23);
24const EMPTY_SERVER_CONFIG_ATOM = Atom.make<ServerConfig | null>(null).pipe(
25 Atom.withLabel("mobile-server-config:empty"),
26);
27
28export function useProjects(): ReadonlyArray<EnvironmentProject> {
29 return useAtomValue(environmentProjects.projectsAtom);
30}
31
32export function useThreadShells(): ReadonlyArray<EnvironmentThreadShell> {
33 return useAtomValue(environmentThreadShells.threadShellsAtom);
34}
35
36export function useProject(ref: ScopedProjectRef | null): EnvironmentProject | null {
37 return useAtomValue(ref === null ? EMPTY_PROJECT_ATOM : environmentProjects.projectAtom(ref));
38}
39
40export function useThreadShell(ref: ScopedThreadRef | null): EnvironmentThreadShell | null {
41 return useAtomValue(
42 ref === null ? EMPTY_THREAD_SHELL_ATOM : environmentThreadShells.threadShellAtom(ref),
43 );
44}
45
46export function useEnvironmentServerConfig(
47 environmentId: EnvironmentId | null,
48): ServerConfig | null {
49 return useAtomValue(
50 environmentId === null
51 ? EMPTY_SERVER_CONFIG_ATOM
52 : serverEnvironment.configValueAtom(environmentId),
53 );
54}
55
56export function useServerConfigs(): ReadonlyMap<EnvironmentId, ServerConfig> {
57 return useAtomValue(environmentServerConfigsAtom);
58}