Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

LegacyThreadMigrationToast.tsx

45 lines1.3 KB

1import { useAtomValue } from "@effect/atom-react";
2import { useEffect, useRef } from "react";
3​
4import { primaryServerLegacyThreadMigrationAtom } from "../state/server";
5import { toastManager } from "./ui/toast";
6​
7type MigrationToastId = ReturnType<typeof toastManager.add>;
8​
9export function LegacyThreadMigrationToast() {
10 const migration = useAtomValue(primaryServerLegacyThreadMigrationAtom);
11 const toastIdRef = useRef<MigrationToastId | null>(null);
12​
13 useEffect(() => {
14 if (migration?.status === "running") {
15 if (toastIdRef.current !== null) {
16 return;
17 }
18 toastIdRef.current = toastManager.add({
19 type: "loading",
20 title: "Restoring your threads…",
21 description: `Migrating ${migration.totalThreadCount.toLocaleString()} ${
22 migration.totalThreadCount === 1 ? "thread" : "threads"
23 } from the previous version. You can keep working while this finishes.`,
24 timeout: 0,
25 });
26 return;
27 }
28​
29 if (toastIdRef.current !== null) {
30 toastManager.close(toastIdRef.current);
31 toastIdRef.current = null;
32 }
33 }, [migration]);
34​
35 useEffect(
36 () => () => {
37 if (toastIdRef.current !== null) {
38 toastManager.close(toastIdRef.current);
39 }
40 },
41 [],
42 );
43​
44 return null;