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

threadHandoff.ts

20 lines970 Bytes

1import { useAtomValue } from "@effect/atom-react";
2import { offersLinkedEnvironments } from "@t3tools/client-runtime/link-request";
3import { createThreadHandoffEnvironmentAtoms } from "@t3tools/client-runtime/state/peerLinks";
4import type { EnvironmentId } from "@t3tools/contracts";
5​
6import { connectionAtomRuntime } from "../connection/runtime";
7import { environmentServerConfigsAtom } from "./server";
8​
9export const threadHandoffEnvironment = createThreadHandoffEnvironmentAtoms(connectionAtomRuntime);
10​
11/** Whether `environmentId` offers links and this app may move its threads over one. */
12export function useCanMoveThreads(environmentId: EnvironmentId | null): boolean {
13 const permitted = useAtomValue(threadHandoffEnvironment.start.permissionAtom(environmentId));
14 return useAtomValue(
15 environmentServerConfigsAtom,
16 (configs) =>
17 permitted &&
18 offersLinkedEnvironments(environmentId === null ? undefined : configs.get(environmentId)),
19 );