import { useAtomValue } from "@effect/atom-react"; import type { EnvironmentProject, EnvironmentThreadShell, } from "@t3tools/client-runtime/state/shell"; import type { EnvironmentId, ScopedProjectRef, ScopedThreadRef, ServerConfig, } from "@t3tools/contracts"; import { Atom } from "effect/unstable/reactivity"; import { environmentProjects } from "./projects"; import { environmentServerConfigsAtom, serverEnvironment } from "./server"; import { environmentThreadShells } from "./threads"; const EMPTY_PROJECT_ATOM = Atom.make(null).pipe( Atom.withLabel("mobile-project:empty"), ); const EMPTY_THREAD_SHELL_ATOM = Atom.make(null).pipe( Atom.withLabel("mobile-thread-shell:empty"), ); const EMPTY_SERVER_CONFIG_ATOM = Atom.make(null).pipe( Atom.withLabel("mobile-server-config:empty"), ); export function useProjects(): ReadonlyArray { return useAtomValue(environmentProjects.projectsAtom); } export function useThreadShells(): ReadonlyArray { return useAtomValue(environmentThreadShells.threadShellsAtom); } export function useProject(ref: ScopedProjectRef | null): EnvironmentProject | null { return useAtomValue(ref === null ? EMPTY_PROJECT_ATOM : environmentProjects.projectAtom(ref)); } export function useThreadShell(ref: ScopedThreadRef | null): EnvironmentThreadShell | null { return useAtomValue( ref === null ? EMPTY_THREAD_SHELL_ATOM : environmentThreadShells.threadShellAtom(ref), ); } export function useEnvironmentServerConfig( environmentId: EnvironmentId | null, ): ServerConfig | null { return useAtomValue( environmentId === null ? EMPTY_SERVER_CONFIG_ATOM : serverEnvironment.configValueAtom(environmentId), ); } export function useServerConfigs(): ReadonlyMap { return useAtomValue(environmentServerConfigsAtom); }