import { useAtomValue } from "@effect/atom-react";import { type ArchivedSnapshotEntry, createArchivedThreadSnapshotsAtomFamily, makeArchivedThreadsEnvironmentKey,} from "@t3tools/client-runtime/state/threads";import type { EnvironmentId } from "@t3tools/contracts";import { useCallback, useMemo } from "react"; import { appAtomRegistry } from "../../state/atom-registry";import { orchestrationEnvironment } from "../../state/orchestration"; function archivedSnapshotAtom(environmentId: EnvironmentId) { return orchestrationEnvironment.archivedShellSnapshot({ environmentId, input: {}, });} const archivedSnapshotsAtom = createArchivedThreadSnapshotsAtomFamily({ getSnapshotAtom: archivedSnapshotAtom, labelPrefix: "mobile:archived-thread-snapshots",}); export function refreshArchivedThreadsForEnvironment(environmentId: EnvironmentId): void { appAtomRegistry.refresh(archivedSnapshotAtom(environmentId));} export function useArchivedThreadSnapshots(environmentIds: ReadonlyArray<EnvironmentId>): { readonly snapshots: ReadonlyArray<ArchivedSnapshotEntry>; readonly error: string | null; readonly isLoading: boolean; readonly refresh: () => void;} { const environmentKey = useMemo( () => makeArchivedThreadsEnvironmentKey(environmentIds), [environmentIds], ); const result = useAtomValue(archivedSnapshotsAtom(environmentKey)); const refresh = useCallback(() => { for (const environmentId of environmentIds) { appAtomRegistry.refresh(archivedSnapshotAtom(environmentId)); } }, [environmentIds]); return { ...result, refresh };}
import { useAtomValue } from "@effect/atom-react";
import {
type ArchivedSnapshotEntry,
createArchivedThreadSnapshotsAtomFamily,
makeArchivedThreadsEnvironmentKey,
} from "@t3tools/client-runtime/state/threads";
import type { EnvironmentId } from "@t3tools/contracts";
import { useCallback, useMemo } from "react";
import { appAtomRegistry } from "../../state/atom-registry";
import { orchestrationEnvironment } from "../../state/orchestration";
function archivedSnapshotAtom(environmentId: EnvironmentId) {
return orchestrationEnvironment.archivedShellSnapshot({
environmentId,
input: {},
});
}
const archivedSnapshotsAtom = createArchivedThreadSnapshotsAtomFamily({
getSnapshotAtom: archivedSnapshotAtom,
labelPrefix: "mobile:archived-thread-snapshots",
});
export function refreshArchivedThreadsForEnvironment(environmentId: EnvironmentId): void {
appAtomRegistry.refresh(archivedSnapshotAtom(environmentId));
}
export function useArchivedThreadSnapshots(environmentIds: ReadonlyArray<EnvironmentId>): {
readonly snapshots: ReadonlyArray<ArchivedSnapshotEntry>;
readonly error: string | null;
readonly isLoading: boolean;
readonly refresh: () => void;
} {
const environmentKey = useMemo(
() => makeArchivedThreadsEnvironmentKey(environmentIds),
[environmentIds],
);
const result = useAtomValue(archivedSnapshotsAtom(environmentKey));
const refresh = useCallback(() => {
for (const environmentId of environmentIds) {
appAtomRegistry.refresh(archivedSnapshotAtom(environmentId));
}
}, [environmentIds]);
return { ...result, refresh };
}