Open History to see the last commit
1import { useAtomRefresh } from "@effect/atom-react";
2import { type EnvironmentId, type ProviderInstanceId } from "@t3tools/contracts";
3import { createProviderWorkspaceSnapshotRefreshAtomFamily } from "@t3tools/client-runtime/providerSkills";
4import { Atom } from "effect/reactivity";
5
6import { serverEnvironment } from "../../state/server";
7
8const providerWorkspaceSnapshotRefresh = createProviderWorkspaceSnapshotRefreshAtomFamily({
9 providers: serverEnvironment.providersValueAtom,
10 refreshProviders: serverEnvironment.refreshProviders,
11});
12
13const idleRefreshAtom: Atom.Atom<unknown> = Atom.make<void>(undefined).pipe(
14 Atom.withLabel("provider-workspace-snapshot-refresh:idle"),
15);
16
17/**
18 * Keeps the selected provider's workspace snapshot fresh for the composer's
19 * cwd while mounted. Returns a check to run when the user types.
20 */
21export function useProviderWorkspaceSnapshotRefresh(input: {
22 readonly environmentId: EnvironmentId;
23 readonly gitCwd: string | null;
24 readonly instanceId: ProviderInstanceId | undefined;
25}): () => void {
26 const { environmentId, gitCwd, instanceId } = input;
27 const atom =
28 gitCwd && instanceId
29 ? providerWorkspaceSnapshotRefresh({ environmentId, instanceId, cwd: gitCwd })
30 : idleRefreshAtom;
31 return useAtomRefresh(atom);
32}