Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

session.ts

21 lines813 Bytes

1import { useAtomValue } from "@effect/atom-react";
2import { createEnvironmentSessionAtoms } from "@t3tools/client-runtime/state/session";
3import type { EnvironmentId } from "@t3tools/contracts";
4import * as Option from "effect/Option";
5import { Atom } from "effect/unstable/reactivity";
6​
7import { connectionAtomRuntime } from "../connection/runtime";
8​
9export const environmentSession = createEnvironmentSessionAtoms(connectionAtomRuntime);
10​
11const EMPTY_PREPARED_CONNECTION_ATOM = Atom.make(Option.none()).pipe(
12 Atom.withLabel("mobile-prepared-connection:empty"),
13);
14​
15export function usePreparedConnection(environmentId: EnvironmentId | null) {
16 return useAtomValue(
17 environmentId === null
18 ? EMPTY_PREPARED_CONNECTION_ATOM
19 : environmentSession.preparedConnectionValueAtom(environmentId),
20 );