diff --git a/src/components/Activity.tsx b/src/components/Activity.tsx index e9781991..588a7d4e 100644 --- a/src/components/Activity.tsx +++ b/src/components/Activity.tsx @@ -1,6 +1,6 @@ import { TagItem } from "@mutinywallet/mutiny-wasm"; import { cache, createAsync, useNavigate } from "@solidjs/router"; -import { Plus, Save, Search, Shuffle, Users } from "lucide-solid"; +import { Plus, Save, Search, Shuffle } from "lucide-solid"; import { createEffect, createMemo, diff --git a/src/routes/settings/ManageFederations.tsx b/src/routes/settings/ManageFederations.tsx index 986fb863..7a33070d 100644 --- a/src/routes/settings/ManageFederations.tsx +++ b/src/routes/settings/ManageFederations.tsx @@ -22,6 +22,7 @@ import { createSignal, For, Match, + onCleanup, onMount, Show, Suspense, @@ -363,6 +364,8 @@ function FederationListItem(props: { } }); + const [shouldPollProgress, setShouldPollProgress] = createSignal(false); + async function resyncFederation() { setResyncLoading(true); try { @@ -370,17 +373,18 @@ function FederationListItem(props: { console.warn("RESYNC STARTED"); + // This loop is so we can try enough times until the resync actually starts for (let i = 0; i < 60; i++) { await timeout(1000); const progress = await sw.get_federation_resync_progress( props.fed.federation_id ); - // FIXME: this only logs once when we start the resync but not after console.log("progress", progress); if (progress?.total !== 0) { setResyncProgress(progress); setResyncOpen(false); + setShouldPollProgress(true); break; } } @@ -390,6 +394,37 @@ function FederationListItem(props: { } } + function refetch() { + sw.get_federation_resync_progress(props.fed.federation_id).then( + (progress) => { + setResyncProgress(progress); + + if (progress?.done) { + setShouldPollProgress(false); + setResyncLoading(false); + } + } + ); + } + + createEffect(() => { + let interval = undefined; + + if (shouldPollProgress()) { + interval = setInterval(() => { + refetch(); + }, 1000); // Poll every second + } + + if (!shouldPollProgress()) { + clearInterval(interval); + } + + onCleanup(() => { + clearInterval(interval); + }); + }); + async function confirmRemove() { setConfirmOpen(true); } @@ -523,14 +558,22 @@ function FederationListItem(props: { title={"Resyncing..."} open={!resyncProgress()!.done} > - This could take a couple of hours. - - DO NOT CLOSE THIS WINDOW UNTIL RESYNC IS DONE. - - + + This could take a couple of hours. + + DO NOT CLOSE THIS WINDOW UNTIL RESYNC IS DONE. + + + + + Resync complete! + +