Browse Source

fetch malls by location

master
kj1352 5 years ago
parent
commit
ae47c8eb8f
1 changed files with 26 additions and 8 deletions
  1. +26
    -8
      src/app/malls/malls.page.ts

+ 26
- 8
src/app/malls/malls.page.ts View File

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


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


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


ngOnInit() { 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() { 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() { searchAllMalls() {
@@ -39,7 +58,7 @@ export class MallsPage implements OnInit {
return mallData.mall.mall_name.toLowerCase().includes(this.searchTerm.toLowerCase()); return mallData.mall.mall_name.toLowerCase().includes(this.searchTerm.toLowerCase());
}); });
} else { } 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) => { this.mallService.allMalls().then((response) => {
localStorage.allMalls = JSON.stringify(response); localStorage.allMalls = JSON.stringify(response);
this.allMalls = JSON.parse(localStorage.allMalls); this.allMalls = JSON.parse(localStorage.allMalls);
this.tempMalls = JSON.parse(localStorage.allMalls);
}, (error) => { }, (error) => {
console.log(error) console.log(error)
}); });


Loading…
Cancel
Save