The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | createIssueEnvironmentAtoms, |
| 3 | createMergedIssueCandidatesAtoms, |
| 4 | createMergedIssueListAtoms, |
| 5 | type IssueCandidatesTarget, |
| 6 | type IssueListTarget, |
| 7 | } from "@t3tools/client-runtime/state/issues"; |
| 8 | import { useAtomValue } from "@effect/atom-react"; |
| 9 | import type { EnvironmentId } from "@t3tools/contracts"; |
| 10 | |
| 11 | import { connectionAtomRuntime } from "../connection/runtime"; |
| 12 | import { appAtomRegistry } from "./atom-registry"; |
| 13 | import { formatEnvironmentQueryError } from "./query"; |
| 14 | |
| 15 | export const issueEnvironment = createIssueEnvironmentAtoms(connectionAtomRuntime); |
| 16 | |
| 17 | const mergedIssueLists = createMergedIssueListAtoms(issueEnvironment, formatEnvironmentQueryError); |
| 18 | |
| 19 | /** One listing read across every environment asked. */ |
| 20 | export function useIssueList(targets: ReadonlyArray<IssueListTarget>) { |
| 21 | const view = useAtomValue(mergedIssueLists.atom(targets)); |
| 22 | return { |
| 23 | ...view, |
| 24 | refresh: () => mergedIssueLists.refresh(appAtomRegistry, targets, "manual"), |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | /** After a write the list cannot see, such as a new issue filed from a sheet. */ |
| 29 | export function refreshIssueLists(environmentId: EnvironmentId) { |
| 30 | mergedIssueLists.refreshEnvironment(appAtomRegistry, environmentId); |
| 31 | } |
| 32 | |
| 33 | const mergedIssueCandidates = createMergedIssueCandidatesAtoms( |
| 34 | issueEnvironment.candidates, |
| 35 | formatEnvironmentQueryError, |
| 36 | ); |
| 37 | |
| 38 | /** The labels and people of every scope a list filter covers; no targets reads nothing. */ |
| 39 | export function useIssueFilterCandidates(targets: ReadonlyArray<IssueCandidatesTarget>) { |
| 40 | return useAtomValue(mergedIssueCandidates.atom(targets)); |
| 41 | } |
| 42 | |
| 43 | /** Asks again only the scopes that failed; the ones that answered keep their answer. */ |
| 44 | export function refreshIssueFilterCandidates(targets: ReadonlyArray<IssueCandidatesTarget>) { |
| 45 | mergedIssueCandidates.retry(appAtomRegistry, targets); |
| 46 | } |