The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { RegistryContext } from "@effect/atom-react"; |
| 2 | import { |
| 3 | executeAtomQuery, |
| 4 | type AtomQueryOptions, |
| 5 | type AtomCommandResult, |
| 6 | } from "@t3tools/client-runtime/state/runtime"; |
| 7 | import { AsyncResult, type Atom } from "effect/reactivity"; |
| 8 | import { useContext } from "react"; |
| 9 | |
| 10 | export function useAtomQueryRunner<T, A, E>( |
| 11 | family: (target: T) => Atom.Atom<AsyncResult.AsyncResult<A, E>>, |
| 12 | options?: string | Omit<AtomQueryOptions, "signal">, |
| 13 | ): (target: T, call?: Pick<AtomQueryOptions, "signal">) => Promise<AtomCommandResult<A, E>> { |
| 14 | const registry = useContext(RegistryContext); |
| 15 | const explicitLabel = typeof options === "string" ? options : options?.label; |
| 16 | const reportFailure = typeof options === "string" ? true : (options?.reportFailure ?? true); |
| 17 | const reportDefect = typeof options === "string" ? true : (options?.reportDefect ?? true); |
| 18 | const refresh = typeof options === "string" ? false : (options?.refresh ?? false); |
| 19 | |
| 20 | return (target, call) => { |
| 21 | const atom = family(target); |
| 22 | return executeAtomQuery(registry, atom, { |
| 23 | label: explicitLabel ?? atom.label?.[0] ?? "atom query", |
| 24 | reportFailure, |
| 25 | reportDefect, |
| 26 | refresh, |
| 27 | ...call, |
| 28 | }); |
| 29 | }; |
| 30 | } |