@@ -22,6 +22,7 @@ import {
22
22
createSignal ,
23
23
For ,
24
24
Match ,
25
+ onCleanup ,
25
26
onMount ,
26
27
Show ,
27
28
Suspense ,
@@ -363,24 +364,27 @@ function FederationListItem(props: {
363
364
}
364
365
} ) ;
365
366
367
+ const [ shouldPollProgress , setShouldPollProgress ] = createSignal ( false ) ;
368
+
366
369
async function resyncFederation ( ) {
367
370
setResyncLoading ( true ) ;
368
371
try {
369
372
await sw . resync_federation ( props . fed . federation_id ) ;
370
373
371
374
console . warn ( "RESYNC STARTED" ) ;
372
375
376
+ // This loop is so we can try enough times until the resync actually starts
373
377
for ( let i = 0 ; i < 60 ; i ++ ) {
374
378
await timeout ( 1000 ) ;
375
379
const progress = await sw . get_federation_resync_progress (
376
380
props . fed . federation_id
377
381
) ;
378
382
379
- // FIXME: this only logs once when we start the resync but not after
380
383
console . log ( "progress" , progress ) ;
381
384
if ( progress ?. total !== 0 ) {
382
385
setResyncProgress ( progress ) ;
383
386
setResyncOpen ( false ) ;
387
+ setShouldPollProgress ( true ) ;
384
388
break ;
385
389
}
386
390
}
@@ -390,6 +394,47 @@ function FederationListItem(props: {
390
394
}
391
395
}
392
396
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
+
393
438
async function confirmRemove ( ) {
394
439
setConfirmOpen ( true ) ;
395
440
}
@@ -523,14 +568,22 @@ function FederationListItem(props: {
523
568
title = { "Resyncing..." }
524
569
open = { ! resyncProgress ( ) ! . done }
525
570
>
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 >
534
587
</ SimpleDialog >
535
588
</ Show >
536
589
</ >
0 commit comments