import { useAtomValue } from "@effect/atom-react"; import { useEffect, useRef } from "react"; import { primaryServerLegacyThreadMigrationAtom } from "../state/server"; import { toastManager } from "./ui/toast"; type MigrationToastId = ReturnType; export function LegacyThreadMigrationToast() { const migration = useAtomValue(primaryServerLegacyThreadMigrationAtom); const toastIdRef = useRef(null); useEffect(() => { if (migration?.status === "running") { if (toastIdRef.current !== null) { return; } toastIdRef.current = toastManager.add({ type: "loading", title: "Restoring your threads…", description: `Migrating ${migration.totalThreadCount.toLocaleString()} ${ migration.totalThreadCount === 1 ? "thread" : "threads" } from the previous version. You can keep working while this finishes.`, timeout: 0, }); return; } if (toastIdRef.current !== null) { toastManager.close(toastIdRef.current); toastIdRef.current = null; } }, [migration]); useEffect( () => () => { if (toastIdRef.current !== null) { toastManager.close(toastIdRef.current); } }, [], ); return null; }