Open History to see the last commit
1import { useAtomValue } from "@effect/atom-react";
2import type { EnvironmentId } from "@t3tools/contracts";
3
4import { environmentCatalog } from "../../connection/catalog";
5import { useAtomCommand } from "../../state/use-atom-command";
6
7export function useRetryEnvironment() {
8 const catalog = useAtomValue(environmentCatalog.catalogValueAtom);
9 const retryNow = useAtomCommand(environmentCatalog.retryNow, "environment retry");
10 const setEnabled = useAtomCommand(environmentCatalog.setEnabled, "environment toggle");
11
12 return (environmentId: EnvironmentId) =>
13 // A retry does nothing while the environment is switched off.
14 catalog.entries.get(environmentId)?.enabled === false
15 ? setEnabled({ environmentId, enabled: true })
16 : retryNow(environmentId);
17}