The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { useAtomValue } from "@effect/atom-react"; |
| 2 | import type { EnvironmentPresentation } from "@t3tools/client-runtime/connection"; |
| 3 | import { |
| 4 | createEnvironmentPresentationAtoms, |
| 5 | createEnvironmentSummaryAtoms, |
| 6 | } from "@t3tools/client-runtime/state/presentation"; |
| 7 | import type { EnvironmentId } from "@t3tools/contracts"; |
| 8 | import { Atom } from "effect/reactivity"; |
| 9 | |
| 10 | import { environmentCatalog } from "../connection/catalog"; |
| 11 | import { environmentServerConfigsAtom, serverEnvironment } from "./server"; |
| 12 | import { createThreadListEnvironmentsAtom } from "./thread-list-environments"; |
| 13 | |
| 14 | export const environmentPresentations = createEnvironmentPresentationAtoms({ |
| 15 | catalogValueAtom: environmentCatalog.catalogValueAtom, |
| 16 | stateAtom: environmentCatalog.stateAtom, |
| 17 | serverConfigValueAtom: serverEnvironment.configValueAtom, |
| 18 | }); |
| 19 | |
| 20 | export const { connectedEnvironmentIdsAtom } = createEnvironmentSummaryAtoms({ |
| 21 | catalogValueAtom: environmentCatalog.catalogValueAtom, |
| 22 | presentationAtom: environmentPresentations.presentationAtom, |
| 23 | }); |
| 24 | |
| 25 | export const threadListEnvironmentsAtom = createThreadListEnvironmentsAtom( |
| 26 | environmentServerConfigsAtom, |
| 27 | connectedEnvironmentIdsAtom, |
| 28 | ); |
| 29 | |
| 30 | const EMPTY_ENVIRONMENT_PRESENTATION_ATOM = Atom.make<EnvironmentPresentation | null>(null).pipe( |
| 31 | Atom.withLabel("mobile-environment-presentation:empty"), |
| 32 | ); |
| 33 | |
| 34 | export function useEnvironmentPresentation(environmentId: EnvironmentId | null) { |
| 35 | const catalog = useAtomValue(environmentCatalog.catalogValueAtom); |
| 36 | const presentation = useAtomValue( |
| 37 | environmentId === null |
| 38 | ? EMPTY_ENVIRONMENT_PRESENTATION_ATOM |
| 39 | : environmentPresentations.presentationAtom(environmentId), |
| 40 | ); |
| 41 | return { |
| 42 | isReady: catalog.isReady, |
| 43 | presentation, |
| 44 | }; |
| 45 | } |