| 1 | import type { EnvironmentPresentation, NetworkStatus } from "@t3tools/client-runtime/connection"; |
| 2 | import type { EnvironmentCatalogState } from "@t3tools/client-runtime/state/connections"; |
| 3 | import type { EnvironmentId } from "@t3tools/contracts"; |
| 4 | import { createEnvironmentSummaryAtoms } from "@t3tools/client-runtime/state/presentation"; |
| 5 | import { Atom } from "effect/reactivity"; |
| 6 | |
| 7 | import { projectWorkspaceConnectionState } from "./workspaceModel"; |
| 8 | |
| 9 | export function createWorkspaceConnectionAtoms(input: { |
| 10 | readonly catalogValueAtom: Atom.Atom<EnvironmentCatalogState>; |
| 11 | readonly networkStatusValueAtom: Atom.Atom<NetworkStatus>; |
| 12 | readonly presentationAtom: ( |
| 13 | environmentId: EnvironmentId, |
| 14 | ) => Atom.Atom<EnvironmentPresentation | null>; |
| 15 | }) { |
| 16 | const { environmentsAtom } = createEnvironmentSummaryAtoms(input); |
| 17 | const isReadyAtom = input.catalogValueAtom.pipe(Atom.map((catalog) => catalog.isReady)); |
| 18 | const stateAtom = Atom.make((get) => |
| 19 | projectWorkspaceConnectionState({ |
| 20 | isReady: get(isReadyAtom), |
| 21 | networkStatus: get(input.networkStatusValueAtom), |
| 22 | environments: get(environmentsAtom), |
| 23 | }), |
| 24 | ).pipe(Atom.withLabel("mobile:workspace-connection-state")); |
| 25 | return { environmentsAtom, stateAtom, isReadyAtom }; |
| 26 | } |