From 7a2885961ef81059ffc0c3fc595a48208933dc65 Mon Sep 17 00:00:00 2001
From: Xiao Gui <xgui3783@gmail.com>
Date: Wed, 8 May 2019 10:52:09 +0200
Subject: [PATCH] chore: reintroduce delay when showing cookie disclaimer modal

you are right daviti, there needs to be a delay when creating
views in lifecycle hooks. but I will be damned if we need to use
setTimeout, and I'd rather use rxjs observable
---
 src/atlasViewer/atlasViewer.component.ts           | 14 ++++++++++----
 .../cookieAgreement/cookieAgreement.component.ts   |  2 +-
 .../cookieAgreement/cookieAgreement.template.html  |  7 +++++--
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/atlasViewer/atlasViewer.component.ts b/src/atlasViewer/atlasViewer.component.ts
index 7d26de77b..c5736694e 100644
--- a/src/atlasViewer/atlasViewer.component.ts
+++ b/src/atlasViewer/atlasViewer.component.ts
@@ -301,14 +301,20 @@ export class AtlasViewer implements OnDestroy, OnInit, AfterViewInit {
     /**
      * Show Cookie disclaimer if not yet agreed
      */
-    if (localStorage.getItem('cookies') !== 'agreed') {
+    /**
+     * TODO avoid creating new views in lifecycle hooks in general
+     */
+    of(localStorage.getItem('cookies') !== 'agreed').pipe(
+      delay(0),
+      filter(flag => flag)
+    ).subscribe(() => {
       this.modalService.show(ModalUnit, {
         initialState: {
           title: 'Cookie Disclaimer',
-          template: this.cookieAgreementComponent,
+          template: this.cookieAgreementComponent
         }
-      }); 
-    }
+      }) 
+    })
 
     this.onhoverSegmentForFixed$ = this.rClContextualMenu.onShow.pipe(
       withLatestFrom(this.onhoverSegment$),
diff --git a/src/ui/cookieAgreement/cookieAgreement.component.ts b/src/ui/cookieAgreement/cookieAgreement.component.ts
index f5ee943ab..e52f59c5b 100644
--- a/src/ui/cookieAgreement/cookieAgreement.component.ts
+++ b/src/ui/cookieAgreement/cookieAgreement.component.ts
@@ -9,5 +9,5 @@ import { Component, ChangeDetectionStrategy } from '@angular/core'
   changeDetection: ChangeDetectionStrategy.OnPush
 })
 export class CookieAgreement {
-  showMore = false;
+  public showMore:boolean = false
 }
\ No newline at end of file
diff --git a/src/ui/cookieAgreement/cookieAgreement.template.html b/src/ui/cookieAgreement/cookieAgreement.template.html
index bfa300960..316ca3d43 100644
--- a/src/ui/cookieAgreement/cookieAgreement.template.html
+++ b/src/ui/cookieAgreement/cookieAgreement.template.html
@@ -11,8 +11,11 @@
   <p>To opt-out of being tracked by Google Analytics across all websites, visit
     <a href="http://tools.google.com/dlpage/gaoptout">http://tools.google.com/dlpage/gaoptout</a> .</p>
 
-  <button class="btn btn-outline-info btn-block mb-2" (click)="showMore = !showMore">Show
-    {{showMore? "less" : "more"}}</button>
+  <button
+    class="btn btn-outline-info btn-block mb-2"
+    (click)="showMore = !showMore">
+    Show {{showMore? "less" : "more"}}
+  </button>
 
   <div *ngIf="showMore">
     <small>
-- 
GitLab