@@ -385,25 +385,31 @@ export default class DeputyRootSession {
385
385
// TODO: Do interface functions
386
386
this . sections = [ ] ;
387
387
388
- const foundSections : string [ ] = [ ] ;
388
+ const activeSectionPromises = [ ] ;
389
389
for ( const heading of this . casePage . findContributionSurveyHeadings ( ) ) {
390
390
const headingName = sectionHeadingName ( heading ) ;
391
391
392
392
if ( this . session . caseSections . indexOf ( headingName ) !== - 1 ) {
393
- foundSections . push ( headingName ) ;
394
- ( ( ) => {
395
- // Placed in self-executing function for asynchronicity.
396
- this . activateSection ( this . casePage , heading ) ;
397
- } ) ( ) ;
393
+ activeSectionPromises . push (
394
+ this . activateSection ( this . casePage , heading )
395
+ . then ( v => v ? headingName : null )
396
+ ) ;
398
397
} else {
399
398
this . addSectionOverlay ( this . casePage , heading ) ;
400
399
}
401
400
}
402
401
403
402
// Strip missing sections from caseSections.
404
- this . session . caseSections = foundSections ;
403
+ this . session . caseSections = ( await Promise . all ( activeSectionPromises ) )
404
+ . filter ( v => ! ! v ) ;
405
405
await DeputyRootSession . setSession ( this . session ) ;
406
406
407
+ if ( this . session . caseSections . length === 0 ) {
408
+ // No sections re-opened. All of them might have been removed or closed already.
409
+ // Close this entire session.
410
+ await this . closeSession ( ) ;
411
+ }
412
+
407
413
res ( ) ;
408
414
} ) ;
409
415
} ) ;
@@ -502,14 +508,15 @@ export default class DeputyRootSession {
502
508
*
503
509
* @param casePage
504
510
* @param heading
511
+ * @return `true` if the section was activated successfully
505
512
*/
506
513
async activateSection (
507
514
casePage : DeputyCasePage ,
508
515
heading : ContributionSurveyHeading
509
- ) : Promise < void > {
516
+ ) : Promise < boolean > {
510
517
const el = new DeputyContributionSurveySection ( casePage , heading ) ;
511
518
if ( ! ( await el . prepare ( ) ) ) {
512
- return ;
519
+ return false ;
513
520
}
514
521
515
522
const sectionName = sectionHeadingName ( heading ) ;
@@ -522,6 +529,8 @@ export default class DeputyRootSession {
522
529
await casePage . addActiveSection ( sectionName ) ;
523
530
524
531
heading . insertAdjacentElement ( 'afterend' , el . render ( ) ) ;
532
+
533
+ return true ;
525
534
}
526
535
527
536
/**
0 commit comments