Skip to content
This repository was archived by the owner on Apr 21, 2025. It is now read-only.

Commit 80cbb81

Browse files
futurepaulbenthecarman
authored andcommitted
add a polling interval and a done state
1 parent 86e0dd0 commit 80cbb81

File tree

2 files changed

+63
-10
lines changed

2 files changed

+63
-10
lines changed

src/components/Activity.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TagItem } from "@mutinywallet/mutiny-wasm";
22
import { cache, createAsync, useNavigate } from "@solidjs/router";
3-
import { Plus, Save, Search, Shuffle, Users } from "lucide-solid";
3+
import { Plus, Save, Search, Shuffle } from "lucide-solid";
44
import {
55
createEffect,
66
createMemo,

src/routes/settings/ManageFederations.tsx

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
createSignal,
2323
For,
2424
Match,
25+
onCleanup,
2526
onMount,
2627
Show,
2728
Suspense,
@@ -363,24 +364,27 @@ function FederationListItem(props: {
363364
}
364365
});
365366

367+
const [shouldPollProgress, setShouldPollProgress] = createSignal(false);
368+
366369
async function resyncFederation() {
367370
setResyncLoading(true);
368371
try {
369372
await sw.resync_federation(props.fed.federation_id);
370373

371374
console.warn("RESYNC STARTED");
372375

376+
// This loop is so we can try enough times until the resync actually starts
373377
for (let i = 0; i < 60; i++) {
374378
await timeout(1000);
375379
const progress = await sw.get_federation_resync_progress(
376380
props.fed.federation_id
377381
);
378382

379-
// FIXME: this only logs once when we start the resync but not after
380383
console.log("progress", progress);
381384
if (progress?.total !== 0) {
382385
setResyncProgress(progress);
383386
setResyncOpen(false);
387+
setShouldPollProgress(true);
384388
break;
385389
}
386390
}
@@ -390,6 +394,47 @@ function FederationListItem(props: {
390394
}
391395
}
392396

397+
function refetch() {
398+
sw.get_federation_resync_progress(props.fed.federation_id).then(
399+
(progress) => {
400+
// if the progress is undefined, it also means we're done
401+
if (progress === undefined) {
402+
setResyncProgress({
403+
total: 100,
404+
complete: 100,
405+
done: true
406+
});
407+
setShouldPollProgress(false);
408+
setResyncLoading(false);
409+
return;
410+
} else if (progress?.done) {
411+
setShouldPollProgress(false);
412+
setResyncLoading(false);
413+
}
414+
415+
setResyncProgress(progress);
416+
}
417+
);
418+
}
419+
420+
createEffect(() => {
421+
let interval = undefined;
422+
423+
if (shouldPollProgress()) {
424+
interval = setInterval(() => {
425+
refetch();
426+
}, 1000); // Poll every second
427+
}
428+
429+
if (!shouldPollProgress()) {
430+
clearInterval(interval);
431+
}
432+
433+
onCleanup(() => {
434+
clearInterval(interval);
435+
});
436+
});
437+
393438
async function confirmRemove() {
394439
setConfirmOpen(true);
395440
}
@@ -523,14 +568,22 @@ function FederationListItem(props: {
523568
title={"Resyncing..."}
524569
open={!resyncProgress()!.done}
525570
>
526-
<NiceP>This could take a couple of hours.</NiceP>
527-
<NiceP>
528-
DO NOT CLOSE THIS WINDOW UNTIL RESYNC IS DONE.
529-
</NiceP>
530-
<ResyncLoadingBar
531-
value={resyncProgress()!.complete}
532-
max={resyncProgress()!.total}
533-
/>
571+
<Show when={!resyncProgress()!.done}>
572+
<NiceP>This could take a couple of hours.</NiceP>
573+
<NiceP>
574+
DO NOT CLOSE THIS WINDOW UNTIL RESYNC IS DONE.
575+
</NiceP>
576+
<ResyncLoadingBar
577+
value={resyncProgress()!.complete}
578+
max={resyncProgress()!.total}
579+
/>
580+
</Show>
581+
<Show when={resyncProgress()!.done}>
582+
<NiceP>Resync complete!</NiceP>
583+
<Button onClick={() => (window.location.href = "/")}>
584+
Nice
585+
</Button>
586+
</Show>
534587
</SimpleDialog>
535588
</Show>
536589
</>

0 commit comments

Comments
 (0)