From 0aca5b2128f5199ac20aad57d9e7743f7d60d135 Mon Sep 17 00:00:00 2001
From: Antonin Coquet <ext.sopra.acoquet@grandlyon.com>
Date: Tue, 13 Apr 2021 10:49:42 +0200
Subject: [PATCH] fix auto reload of structure

---
 src/app/carto/carto.component.ts               | 18 +++++++++++++-----
 .../components/search/search.component.ts      |  2 --
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/app/carto/carto.component.ts b/src/app/carto/carto.component.ts
index d55b420b7..5d771dc45 100644
--- a/src/app/carto/carto.component.ts
+++ b/src/app/carto/carto.component.ts
@@ -8,6 +8,7 @@ import { Filter } from '../structure-list/models/filter.model';
 import { GeoJson } from '../map/models/geojson.model';
 import { GeojsonService } from '../services/geojson.service';
 import { CustomRegExp } from '../utils/CustomRegExp';
+import { ActivatedRoute } from '@angular/router';
 
 @Component({
   selector: 'app-carto',
@@ -26,14 +27,21 @@ export class CartoComponent implements OnInit {
   public isMapPhone = false;
   public searchedValue = null;
   public locate = false; // Use to sync location between search and map
-  constructor(private structureService: StructureService, private geoJsonService: GeojsonService) {}
+  constructor(
+    private structureService: StructureService,
+    private geoJsonService: GeojsonService,
+    private activatedRoute: ActivatedRoute
+  ) {}
 
   ngOnInit(): void {
-    if (navigator.geolocation) {
-      this.getLocation();
-    } else {
-      this.getStructures(null);
+    if (!this.activatedRoute.snapshot.queryParamMap.get('search')) {
+      if (navigator.geolocation) {
+        this.getLocation();
+      } else {
+        this.getStructures(null);
+      }
     }
+
     if (history.state.data) {
       this.currentStructure = new Structure(history.state.data);
     }
diff --git a/src/app/structure-list/components/search/search.component.ts b/src/app/structure-list/components/search/search.component.ts
index 82e9ec82e..a0a863b10 100644
--- a/src/app/structure-list/components/search/search.component.ts
+++ b/src/app/structure-list/components/search/search.component.ts
@@ -61,7 +61,6 @@ export class SearchComponent implements OnInit, OnChanges {
     this.categories = [];
     this.checkedModulesFilter = new Array();
     if (this.queryString) {
-      console.log('we search', this.queryString);
       const filters: Filter[] = [];
       filters.push(new Filter('query', this.queryString));
       this.searchEvent.emit(filters);
@@ -97,7 +96,6 @@ export class SearchComponent implements OnInit, OnChanges {
       this.location.go('/acteurs');
     }
     this.queryString = this.activatedRoute.snapshot.queryParamMap.get('search');
-    console.log('query string is:', this.queryString);
     const filters: Filter[] = [];
     if (term) {
       filters.push(new Filter('query', term));
-- 
GitLab