Przeglądaj źródła

fetch malls by location

master
kj1352 5 lat temu
rodzic
commit
ae47c8eb8f
1 zmienionych plików z 26 dodań i 8 usunięć
  1. +26
    -8
      src/app/malls/malls.page.ts

+ 26
- 8
src/app/malls/malls.page.ts Wyświetl plik

@@ -1,6 +1,7 @@
import { Component, OnInit, ViewChild,ElementRef } from '@angular/core';
import { MallService } from '../services/mall.service';
import { Router } from '@angular/router';
import { Geolocation } from '@ionic-native/geolocation/ngx';

@Component({
selector: 'app-malls',
@@ -12,6 +13,7 @@ export class MallsPage implements OnInit {
selected_tab: string = 'you';
tempMalls: any = [];
allMalls: any = [];
nearByMalls: any = [];
show_sort_popup: boolean = false;
showSearchBar: boolean = false;
selected_sort: string = null;
@@ -19,18 +21,35 @@ export class MallsPage implements OnInit {

constructor(
private mallService: MallService,
private router: Router
private router: Router,
private geolocation: Geolocation
) { }

ngOnInit() {
this.storeAllMalls();
this.fetchMallsByLocation();
this.storeAllMalls();
}

fetchMallsByLocation() {
this.geolocation.getCurrentPosition().then((position) => {
this.mallService.mallsByLocation(position.coords.latitude, position.coords.longitude)
.then((response) => {
this.nearByMalls = response;
this.tempMalls = response;
})
});
}

toggleSearchBar() {
this.showSearchBar = !this.showSearchBar;
setTimeout(()=>{ // this will make the execution after the above boolean has changed
this.searchElement.nativeElement.focus();
}, 1);
if (this.searchTerm.length > 0) {
this.searchTerm = '';
} else {
this.showSearchBar = !this.showSearchBar;
this.fetchMallsByLocation();
setTimeout(()=>{ // this will make the execution after the above boolean has changed
this.searchElement.nativeElement.focus();
}, 1000);
}
}

searchAllMalls() {
@@ -39,7 +58,7 @@ export class MallsPage implements OnInit {
return mallData.mall.mall_name.toLowerCase().includes(this.searchTerm.toLowerCase());
});
} else {
this.tempMalls = JSON.parse(JSON.stringify(this.allMalls));
this.tempMalls = JSON.parse(JSON.stringify(this.nearByMalls));
}
}

@@ -47,7 +66,6 @@ export class MallsPage implements OnInit {
this.mallService.allMalls().then((response) => {
localStorage.allMalls = JSON.stringify(response);
this.allMalls = JSON.parse(localStorage.allMalls);
this.tempMalls = JSON.parse(localStorage.allMalls);
}, (error) => {
console.log(error)
});


Ładowanie…
Anuluj
Zapisz