diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 0c9a211..e301fc2 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -10,6 +10,7 @@ import { HttpClientModule } from '@angular/common/http'; // Services import import { MallService } from './services/mall.service'; +import { ToastService } from './services/toast.service'; import { AppComponent } from './app.component'; import { AppRoutingModule } from './app-routing.module'; @@ -34,6 +35,7 @@ import { Geolocation } from '@ionic-native/geolocation/ngx'; SplashScreen, MallService, Geolocation, + ToastService, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy } ], bootstrap: [AppComponent] diff --git a/src/app/malls/malls.page.ts b/src/app/malls/malls.page.ts index 50291de..612382f 100644 --- a/src/app/malls/malls.page.ts +++ b/src/app/malls/malls.page.ts @@ -1,7 +1,6 @@ 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', @@ -13,7 +12,6 @@ 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; @@ -21,34 +19,22 @@ export class MallsPage implements OnInit { constructor( private mallService: MallService, - private router: Router, - private geolocation: Geolocation + private router: Router ) { } ngOnInit() { - this.fetchMallsByLocation(); - this.storeAllMalls(); + 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() { if (this.searchTerm.length > 0) { this.searchTerm = ''; + this.tempMalls = JSON.parse(JSON.stringify(this.allMalls)); } else { this.showSearchBar = !this.showSearchBar; - this.fetchMallsByLocation(); setTimeout(()=>{ // this will make the execution after the above boolean has changed this.searchElement.nativeElement.focus(); - }, 1000); + }, 1); } } @@ -58,7 +44,7 @@ export class MallsPage implements OnInit { return mallData.mall.mall_name.toLowerCase().includes(this.searchTerm.toLowerCase()); }); } else { - this.tempMalls = JSON.parse(JSON.stringify(this.nearByMalls)); + this.tempMalls = JSON.parse(JSON.stringify(this.allMalls)); } } @@ -66,6 +52,7 @@ 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) }); diff --git a/src/app/services/toast.service.spec.ts b/src/app/services/toast.service.spec.ts new file mode 100644 index 0000000..2dc86dd --- /dev/null +++ b/src/app/services/toast.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { ToastService } from './toast.service'; + +describe('ToastService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: ToastService = TestBed.get(ToastService); + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/toast.service.ts b/src/app/services/toast.service.ts new file mode 100644 index 0000000..e8d29a0 --- /dev/null +++ b/src/app/services/toast.service.ts @@ -0,0 +1,24 @@ +import { Injectable } from '@angular/core'; +import { ToastController } from '@ionic/angular'; + +@Injectable({ + providedIn: 'root' +}) +export class ToastService { + + constructor(public toastController: ToastController) { } + + async presentToast(message: string, color?: string) { + const toast = await this.toastController.create({ + message: message, + position: 'bottom', + duration: 4000, + color: color? color: 'danger', + buttons: [{ + text: 'OK', + role: 'cancel', + }] + }); + toast.present(); + } +}