From 2362bd286e2a20d29d6865399f63dbbb50fdbc79 Mon Sep 17 00:00:00 2001
From: Hugo SUBTIL <ext.sopra.husubtil@grandlyon.com>
Date: Wed, 4 Nov 2020 09:06:42 +0100
Subject: [PATCH] fix: handling of modal open

---
 .../components/search/search.component.html   |  2 +-
 .../components/search/search.component.ts     | 20 +++++++++----------
 2 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/src/app/structure-list/components/search/search.component.html b/src/app/structure-list/components/search/search.component.html
index 8915f8038..367f9dae1 100644
--- a/src/app/structure-list/components/search/search.component.html
+++ b/src/app/structure-list/components/search/search.component.html
@@ -63,7 +63,7 @@
       <div class="arrow"></div>
     </button>
   </div>
-  <div *ngIf="modalTypeOpened != null">
+  <div *ngIf="isOpenModal">
     <app-modal-filter
       [modalType]="modalTypeOpened"
       [categories]="categories"
diff --git a/src/app/structure-list/components/search/search.component.ts b/src/app/structure-list/components/search/search.component.ts
index 783819ea6..a8b05a667 100644
--- a/src/app/structure-list/components/search/search.component.ts
+++ b/src/app/structure-list/components/search/search.component.ts
@@ -121,20 +121,18 @@ export class SearchComponent implements OnInit {
   // Open the modal and display the list according to the right filter button
   public openModal(modalType: TypeModal): void {
     this.categories = [];
-    if (this.modalTypeOpened !== modalType) {
-      if (!this.isOpenModal) {
-        this.modalTypeOpened = modalType;
-        this.fakeData(modalType);
-        this.isOpenModal = true;
-      } else {
-        this.isOpenModal = false;
-      }
-    } else {
-      this.modalTypeOpened = null;
+    // if modal already closed, reset type
+    if (this.modalTypeOpened === modalType && !this.isOpenModal) {
+      this.modalTypeOpened = undefined;
+    } else if (!this.isOpenModal && this.modalTypeOpened !== modalType) {
+      this.modalTypeOpened = modalType;
+      this.fakeData(modalType);
+      this.isOpenModal = true;
     }
   }
+
   public closeModal(): void {
-    this.modalTypeOpened = null;
+    this.isOpenModal = false;
   }
 
   private fromStringToIdExcel(categ: string): string {
-- 
GitLab