32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
import { useAtomValue } from "@effect/atom-react";
|
|
import type { EnvironmentPresentation } from "@t3tools/client-runtime/connection";
|
|
import { createEnvironmentPresentationAtoms } from "@t3tools/client-runtime/state/presentation";
|
|
import type { EnvironmentId } from "@t3tools/contracts";
|
|
import { Atom } from "effect/unstable/reactivity";
|
|
|
|
import { environmentCatalog } from "../connection/catalog";
|
|
import { serverEnvironment } from "./server";
|
|
|
|
export const environmentPresentations = createEnvironmentPresentationAtoms({
|
|
catalogValueAtom: environmentCatalog.catalogValueAtom,
|
|
stateAtom: environmentCatalog.stateAtom,
|
|
serverConfigValueAtom: serverEnvironment.configValueAtom,
|
|
});
|
|
|
|
const EMPTY_ENVIRONMENT_PRESENTATION_ATOM = Atom.make<EnvironmentPresentation | null>(null).pipe(
|
|
Atom.withLabel("mobile-environment-presentation:empty"),
|
|
);
|
|
|
|
export function useEnvironmentPresentation(environmentId: EnvironmentId | null) {
|
|
const catalog = useAtomValue(environmentCatalog.catalogValueAtom);
|
|
const presentation = useAtomValue(
|
|
environmentId === null
|
|
? EMPTY_ENVIRONMENT_PRESENTATION_ATOM
|
|
: environmentPresentations.presentationAtom(environmentId),
|
|
);
|
|
return {
|
|
isReady: catalog.isReady,
|
|
presentation,
|
|
};
|
|
}
|