Browse Source

Added loaders for better UX

master
kj1352 5 years ago
parent
commit
c808801396
5 changed files with 117 additions and 22 deletions
  1. +26
    -1
      src/app/forgot-password/forgot-password.page.ts
  2. +21
    -2
      src/app/login/login.page.ts
  3. +17
    -1
      src/app/malls/malls.page.ts
  4. +31
    -6
      src/app/onboarding/onboarding.page.ts
  5. +22
    -12
      src/app/orders/orders.component.ts

+ 26
- 1
src/app/forgot-password/forgot-password.page.ts View File

@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { AuthService } from '../services/auth.service'; import { AuthService } from '../services/auth.service';
import { ToastService } from '../services/toast.service'; import { ToastService } from '../services/toast.service';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { LoadingController } from '@ionic/angular';


@Component({ @Component({
selector: 'app-forgot-password', selector: 'app-forgot-password',
@@ -13,35 +14,55 @@ export class ForgotPasswordPage implements OnInit {
otp: string | number = ''; otp: string | number = '';
newPassword: string = ''; newPassword: string = '';


loader: any;

stepType: 'EMAIL' | 'OTP' | 'RESET' = 'EMAIL'; stepType: 'EMAIL' | 'OTP' | 'RESET' = 'EMAIL';


constructor( constructor(
private authService: AuthService, private authService: AuthService,
private toastService: ToastService, private toastService: ToastService,
private router: Router
private router: Router,
public loadingController: LoadingController
) { } ) { }


ngOnInit() { ngOnInit() {
} }


async presentLoading() {
this.loader = await this.loadingController.create({
message: 'Please wait...',
spinner: 'dots',
mode: 'ios'
});
await this.loader.present();
}

ionViewDidEnter() { ionViewDidEnter() {
document.querySelector('.menu-icon-holder').classList.add('hide'); document.querySelector('.menu-icon-holder').classList.add('hide');
} }


getOtp() { getOtp() {
this.presentLoading();
this.authService.forgotPassword(this.email).then(() => { this.authService.forgotPassword(this.email).then(() => {
this.loader.dismiss();
this.toastService.presentToast("OTP Sent to your Email ID", "success"); this.toastService.presentToast("OTP Sent to your Email ID", "success");
this.stepType = 'OTP'; this.stepType = 'OTP';
}, () => { }, () => {
this.loader.dismiss();
this.toastService.presentToast("Failed to send OTP, Please check your credentials", "danger"); this.toastService.presentToast("Failed to send OTP, Please check your credentials", "danger");
}); });
} }


verifyOtp() { verifyOtp() {
this.presentLoading();
this.authService.validateOtpForForgotPassword({ email: this.email, otp: this.otp }).then(() => { this.authService.validateOtpForForgotPassword({ email: this.email, otp: this.otp }).then(() => {
this.toastService.presentToast("Verified", "success"); this.toastService.presentToast("Verified", "success");
this.stepType = 'RESET'; this.stepType = 'RESET';
this.loader.dismiss();
}, () => { }, () => {
this.loader.dismiss();
this.toastService.presentToast("Verification failed, please try again", "danger"); this.toastService.presentToast("Verification failed, please try again", "danger");
}); });
} }
@@ -54,11 +75,15 @@ export class ForgotPasswordPage implements OnInit {
reEnteredPassword: this.newPassword reEnteredPassword: this.newPassword
}; };


this.presentLoading();

this.authService.resetPasswordForEmail(credentials).then(() => { this.authService.resetPasswordForEmail(credentials).then(() => {
this.loader.dismiss();
this.toastService.presentToast("Password Reset Complete", "success"); this.toastService.presentToast("Password Reset Complete", "success");
this.router.navigate(['/login']); this.router.navigate(['/login']);
this.stepType = 'EMAIL'; this.stepType = 'EMAIL';
}, () => { }, () => {
this.loader.dismiss();
this.toastService.presentToast("Please check your password", "danger"); this.toastService.presentToast("Please check your password", "danger");
}); });
} }


+ 21
- 2
src/app/login/login.page.ts View File

@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { AuthService } from '../services/auth.service'; import { AuthService } from '../services/auth.service';
import { ToastService } from '../services/toast.service'; import { ToastService } from '../services/toast.service';
import { LoadingController } from '@ionic/angular';


@Component({ @Component({
selector: 'app-login', selector: 'app-login',
@@ -17,16 +18,28 @@ export class LoginPage implements OnInit {


show_password = false; show_password = false;


loader: any;

constructor( constructor(
private router: Router, private router: Router,
private authService: AuthService, private authService: AuthService,
public toastService: ToastService
public toastService: ToastService,
public loadingController: LoadingController
) { } ) { }


ionViewDidEnter() { ionViewDidEnter() {
document.querySelector('.menu-icon-holder').classList.add('hide'); document.querySelector('.menu-icon-holder').classList.add('hide');
} }


async presentLoading() {
this.loader = await this.loadingController.create({
message: 'Please wait...',
spinner: 'dots',
mode: 'ios'
});
await this.loader.present();
}

ngOnInit() { ngOnInit() {
} }


@@ -35,13 +48,19 @@ export class LoginPage implements OnInit {
} }


login() { login() {
this.presentLoading();
this.authService.authenticateUser(this.credentials).then((data: any) => { this.authService.authenticateUser(this.credentials).then((data: any) => {
localStorage.userInfo = JSON.stringify(data); localStorage.userInfo = JSON.stringify(data);
localStorage.access_Token = data.access_Token; localStorage.access_Token = data.access_Token;

this.loader.dismiss();

this.router.navigate(['/malls']); this.router.navigate(['/malls']);
document.querySelector('.menu-icon-holder').classList.remove('hide'); document.querySelector('.menu-icon-holder').classList.remove('hide');
}, (err) => { }, (err) => {
console.log(err);
this.loader.dismiss();

this.toastService.presentToast('Please check your credentials', 'danger'); this.toastService.presentToast('Please check your credentials', 'danger');
}) })
} }


+ 17
- 1
src/app/malls/malls.page.ts View File

@@ -2,6 +2,7 @@ import { Component, OnInit, ViewChild,ElementRef } from '@angular/core';
import { MallService } from '../services/mall.service'; import { MallService } from '../services/mall.service';
import { ToastService } from '../services/toast.service'; import { ToastService } from '../services/toast.service';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { LoadingController } from '@ionic/angular';


@Component({ @Component({
selector: 'app-malls', selector: 'app-malls',
@@ -18,13 +19,23 @@ export class MallsPage implements OnInit {
selected_sort: string = null; selected_sort: string = null;
searchTerm: string = ''; searchTerm: string = '';
selectedFoodType: string = ''; selectedFoodType: string = '';
loader: any;


constructor( constructor(
private mallService: MallService, private mallService: MallService,
private router: Router, private router: Router,
private toastService: ToastService
private toastService: ToastService,
public loadingController: LoadingController
) { } ) { }


async presentLoading() {
this.loader = await this.loadingController.create({
message: 'Please wait...',
spinner: 'dots',
mode: 'ios'
});
await this.loader.present();
}
getMallsByFoodType(type: string) { getMallsByFoodType(type: string) {
this.selectedFoodType = type; this.selectedFoodType = type;
@@ -103,16 +114,19 @@ export class MallsPage implements OnInit {
getMallsByLocation() { getMallsByLocation() {
if (navigator.geolocation) { if (navigator.geolocation) {
this.toastService.presentToast("Getting malls based on your location...", "dark"); this.toastService.presentToast("Getting malls based on your location...", "dark");
this.presentLoading();
navigator.geolocation.getCurrentPosition((position) => { navigator.geolocation.getCurrentPosition((position) => {
this.mallService.mallsByLocation(position.coords.latitude, position.coords.longitude).then((response: any) => { this.mallService.mallsByLocation(position.coords.latitude, position.coords.longitude).then((response: any) => {
if (response.length > 0) { if (response.length > 0) {
this.allMalls = response; this.allMalls = response;
this.tempMalls = response; this.tempMalls = response;
this.loader.dismiss();
} else { } else {
this.toastService.presentToast("No malls near you your location, Getting all the malls...", "warning"); this.toastService.presentToast("No malls near you your location, Getting all the malls...", "warning");
this.getAllMalls(); this.getAllMalls();
} }
}, () => { }, () => {
this.loader.dismiss();
this.toastService.presentToast("Failed to fetch malls for your location", "danger"); this.toastService.presentToast("Failed to fetch malls for your location", "danger");
}); });
}); });
@@ -125,7 +139,9 @@ export class MallsPage implements OnInit {
this.mallService.allMalls().then((response) => { this.mallService.allMalls().then((response) => {
this.allMalls = response; this.allMalls = response;
this.tempMalls = response; this.tempMalls = response;
this.loader.dismiss();
}, (error) => { }, (error) => {
this.loader.dismiss();
console.log(error); console.log(error);
}); });
} }


+ 31
- 6
src/app/onboarding/onboarding.page.ts View File

@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { AuthService } from '../services/auth.service'; import { AuthService } from '../services/auth.service';
import { ToastService } from '../services/toast.service'; import { ToastService } from '../services/toast.service';
import { LoadingController } from '@ionic/angular';


@Component({ @Component({
selector: 'app-onboarding', selector: 'app-onboarding',
@@ -27,11 +28,23 @@ export class OnboardingPage implements OnInit {
has_special = false; has_special = false;
otp: string = ''; otp: string = '';


loader: any;

constructor( constructor(
private router: Router, private router: Router,
private authService: AuthService, private authService: AuthService,
public toastService: ToastService
) { }
public toastService: ToastService,
public loadingController: LoadingController
) { }

async presentLoading() {
this.loader = await this.loadingController.create({
message: 'Please wait...',
spinner: 'dots',
mode: 'ios'
});
await this.loader.present();
}


ionViewDidEnter() { ionViewDidEnter() {
document.querySelector('.menu-icon-holder').classList.add('hide'); document.querySelector('.menu-icon-holder').classList.add('hide');
@@ -83,27 +96,35 @@ export class OnboardingPage implements OnInit {
} }


validateUser() { validateUser() {
this.authService.validateOtpForEmail({ email: this.credentials.email, otp: this.otp }).then((data) => {
console.log(data);
this.presentLoading();

this.authService.validateOtpForEmail({ email: this.credentials.email, otp: this.otp }).then(() => {
this.loader.dismiss();
this.toastService.presentToast("Verified!", "success"); this.toastService.presentToast("Verified!", "success");
this.nextPage(); this.nextPage();
}, (err) => { }, (err) => {
this.loader.dismiss();
console.log(err); console.log(err);
this.toastService.presentToast("Failed to verify, try again", "danger"); this.toastService.presentToast("Failed to verify, try again", "danger");
}) })
} }


registerUser() { registerUser() {
this.authService.signupUser(this.credentials).then((data) => {
console.log(data);
this.presentLoading();

this.authService.signupUser(this.credentials).then(() => {
this.loader.dismiss();
this.nextPage(); this.nextPage();
}, (err) => { }, (err) => {
console.log(err); console.log(err);
this.loader.dismiss();
this.toastService.presentToast("Failed to create user", "danger"); this.toastService.presentToast("Failed to create user", "danger");
}); });
} }


autoLogin() { autoLogin() {
this.presentLoading();

this.authService.authenticateUser({ this.authService.authenticateUser({
username: this.credentials.username, username: this.credentials.username,
password: this.credentials.password, password: this.credentials.password,
@@ -111,9 +132,13 @@ export class OnboardingPage implements OnInit {
}).then((data: any) => { }).then((data: any) => {
localStorage.userInfo = JSON.stringify(data); localStorage.userInfo = JSON.stringify(data);
localStorage.access_Token = data.access_Token; localStorage.access_Token = data.access_Token;

this.loader.dismiss();

this.router.navigate(['/malls']); this.router.navigate(['/malls']);
document.querySelector('.menu-icon-holder').classList.remove('hide'); document.querySelector('.menu-icon-holder').classList.remove('hide');
}, (err) => { }, (err) => {
this.loader.dismiss();
console.log(err); console.log(err);
this.toastService.presentToast('Please check your credentials', 'danger'); this.toastService.presentToast('Please check your credentials', 'danger');
}) })


+ 22
- 12
src/app/orders/orders.component.ts View File

@@ -4,6 +4,7 @@ import * as moment from 'moment';
import { ICart } from '../cart/cart.page'; import { ICart } from '../cart/cart.page';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ToastService } from '../services/toast.service'; import { ToastService } from '../services/toast.service';
import { LoadingController } from '@ionic/angular';


@Component({ @Component({
selector: 'app-orders', selector: 'app-orders',
@@ -30,12 +31,24 @@ export class OrdersComponent implements OnInit {
rating: null, rating: null,
}; };


loader: any;

constructor( constructor(
private orderService: OrderService, private orderService: OrderService,
private router: Router, private router: Router,
private toastService: ToastService
private toastService: ToastService,
public loadingController: LoadingController
) { } ) { }


async presentLoading() {
this.loader = await this.loadingController.create({
message: 'Please wait...',
spinner: 'dots',
mode: 'ios'
});
await this.loader.present();
}

submitFeedbackForOrder() { submitFeedbackForOrder() {
this.tempReview.app_user.user_id = this.userInfo.id; this.tempReview.app_user.user_id = this.userInfo.id;
@@ -64,16 +77,7 @@ export class OrdersComponent implements OnInit {


}, () => { }, () => {
this.toastService.presentToast("Failed to send review", "danger"); this.toastService.presentToast("Failed to send review", "danger");
});
// this.selectedOrder = null;
// this.tempReview = {
// app_user: {
// user_id: null
// },
// comment: '',
// rating: null,
// };
});
} }


getOrderInUsercardFormat(orderedlist: any) { getOrderInUsercardFormat(orderedlist: any) {
@@ -99,11 +103,17 @@ export class OrdersComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.userInfo = JSON.parse(localStorage.userInfo)['User Info']; this.userInfo = JSON.parse(localStorage.userInfo)['User Info'];


this.presentLoading();

this.orderService.getOrders(this.userInfo.id).then((resp: any)=> { this.orderService.getOrders(this.userInfo.id).then((resp: any)=> {
this.userOrders = resp.reverse();
this.userOrders = resp.reverse();
this.loader ? this.loader.dismiss() : null;
}, (err) => { }, (err) => {
console.log(err); console.log(err);
this.toastService.presentToast("Failed to get orders"); this.toastService.presentToast("Failed to get orders");

this.loader ? this.loader.dismiss() : null;
}); });
this.orderService.getAllOrderStatus().then((data) => { this.orderService.getAllOrderStatus().then((data) => {


Loading…
Cancel
Save