From f1e358bd63e57f6d9f6bb55c541de40031edd7ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Didem=20=C3=96ng=C3=BC?= Date: Tue, 18 Dec 2018 13:32:26 +0300 Subject: [PATCH] frontend(profile): Add toast messages when user enters incorrect input --- frontend/package.json | 2 +- frontend/src/app/app.module.ts | 2 +- .../src/app/auth/pages/signin/signin.page.ts | 16 ++++++++++--- .../pages/event-create/event-create.page.ts | 14 ++++++++++- .../app/profile/pages/public/public.page.ts | 24 ++++++++++++++++++- .../profile/pages/settings/settings.page.ts | 17 +++++++++++-- 6 files changed, 66 insertions(+), 9 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index d2c60163..0fd62f2e 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -89,4 +89,4 @@ "browser" ] } -} \ No newline at end of file +} diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index 61be94ba..0242b7ca 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -23,7 +23,7 @@ import { AppRoutingModule } from './app-routing.module'; AuthModule.forRoot(), DataModule.forRoot(), AppConfigModule, - AppRoutingModule, + AppRoutingModule ], providers: [ StatusBar, diff --git a/frontend/src/app/auth/pages/signin/signin.page.ts b/frontend/src/app/auth/pages/signin/signin.page.ts index 1baa0ece..618ed65c 100755 --- a/frontend/src/app/auth/pages/signin/signin.page.ts +++ b/frontend/src/app/auth/pages/signin/signin.page.ts @@ -1,4 +1,6 @@ import { Component, OnInit } from '@angular/core'; + +import { ToastController } from '@ionic/angular'; import { Validators, FormBuilder, FormGroup } from '@angular/forms'; import { Router, ActivatedRoute } from '@angular/router'; @@ -15,7 +17,8 @@ export class SigninPage implements OnInit { constructor(private formBuilder: FormBuilder, private router: Router, private route: ActivatedRoute, private authService: AuthService, - private alertController: AlertController) { + private alertController: AlertController, + public toastController: ToastController) { this.form = this.formBuilder.group( { email: ['', [Validators.required, Validators.email]], @@ -39,8 +42,15 @@ export class SigninPage implements OnInit { }, error => { console.log(error); + this.presentToast(); }); } - - + async presentToast() { + const toast = await this.toastController.create({ + position: 'top', + message: 'Wrong email or password.', + duration: 2000 + }); + toast.present(); + } } diff --git a/frontend/src/app/events/pages/event-create/event-create.page.ts b/frontend/src/app/events/pages/event-create/event-create.page.ts index 30b355b0..24dbf11e 100644 --- a/frontend/src/app/events/pages/event-create/event-create.page.ts +++ b/frontend/src/app/events/pages/event-create/event-create.page.ts @@ -1,6 +1,7 @@ import {Component, ElementRef, OnInit, ViewChild} from '@angular/core'; import {FormBuilder, FormGroup, Validators, FormArray} from '@angular/forms'; import { Router } from '@angular/router'; +import { ToastController } from '@ionic/angular'; import { EventService } from '../../../data/providers/event/event.service'; @@ -26,7 +27,8 @@ export class EventCreatePage implements OnInit { private eventService: EventService, private router: Router, private alertController: AlertController, - private authService: AuthService) { + private authService: AuthService, + public toastController: ToastController) { this.form = this.formBuilder.group({ medias: this.formBuilder.array([ this.formBuilder.control('', Validators.required) @@ -77,6 +79,7 @@ export class EventCreatePage implements OnInit { message => { this.router.navigate(['/feed']); this.eventPosted = true; + this.presentToast(); }, error => { this.handleError(error) @@ -85,6 +88,15 @@ export class EventCreatePage implements OnInit { } + async presentToast() { + const toast = await this.toastController.create({ + position: 'top', + message: 'Event has been created.', + duration: 2000 + }); + toast.present(); + } + async presentAlert(errMessage ,backendError : boolean) { let alert; diff --git a/frontend/src/app/profile/pages/public/public.page.ts b/frontend/src/app/profile/pages/public/public.page.ts index eb25d4b7..5e3a423f 100644 --- a/frontend/src/app/profile/pages/public/public.page.ts +++ b/frontend/src/app/profile/pages/public/public.page.ts @@ -2,6 +2,7 @@ import {ChangeDetectorRef, Component, OnInit} from '@angular/core'; import {User} from '../../../interfaces'; import {ActivatedRoute} from '@angular/router'; import {AuthService} from '../../../auth/providers/auth/auth.service'; +import { ToastController } from '@ionic/angular'; @Component({ selector: 'app-public', @@ -19,7 +20,7 @@ export class PublicPage implements OnInit { errorMessage : string; error : boolean = false; sameUser : boolean = false; - constructor(private route : ActivatedRoute, private auth : AuthService, private ref: ChangeDetectorRef) { } + constructor(private route : ActivatedRoute, private auth : AuthService, private ref: ChangeDetectorRef,public toastController: ToastController) { } ngOnInit() { this.sub = this.route.params.subscribe(params => { @@ -56,6 +57,7 @@ export class PublicPage implements OnInit { console.log(res); this.isFollowing = true; this.ref.detectChanges(); + this.presentToastFollow(); }, (err)=>{ console.log(err); @@ -72,6 +74,7 @@ export class PublicPage implements OnInit { console.log(res); this.isFollowing = false; this.ref.detectChanges(); + this.presentToastUnfollow(); }, (err)=>{ console.log(err); @@ -80,4 +83,23 @@ export class PublicPage implements OnInit { } } + + async presentToastFollow() { + const toast = await this.toastController.create({ + position: 'top', + message: 'User has been followed.', + duration: 2000 + }); + toast.present(); + } + + async presentToastUnfollow() { + const toast = await this.toastController.create({ + position: 'top', + message: 'User has been unfollowed.', + duration: 2000 + }); + toast.present(); + } + } diff --git a/frontend/src/app/profile/pages/settings/settings.page.ts b/frontend/src/app/profile/pages/settings/settings.page.ts index 8561bcad..1f367e54 100644 --- a/frontend/src/app/profile/pages/settings/settings.page.ts +++ b/frontend/src/app/profile/pages/settings/settings.page.ts @@ -5,6 +5,8 @@ import {Datetime} from '@ionic/angular'; import {Router} from '@angular/router'; import {FormBuilder, FormGroup, Validators} from '@angular/forms'; +import { ToastController } from '@ionic/angular'; + @Component({ selector: 'profile-settings', templateUrl: './settings.page.html', @@ -42,7 +44,8 @@ export class SettingsPage implements OnInit { private sub : any; userId : string | null = null; constructor(private authController: AuthService, private router: - Router, private formBuilder : FormBuilder, private ref: ChangeDetectorRef) { + Router, private formBuilder : FormBuilder, private ref: ChangeDetectorRef, + public toastController: ToastController) { this.form = this.formBuilder.group( { name: ['', [Validators.required, Validators.pattern('[ a-zA-Z]*')]], @@ -109,7 +112,7 @@ export class SettingsPage implements OnInit { console.log(this.userId + ': ' + JSON.stringify(newUser)); this.authController.updateUser(this.user._id, newUser).subscribe((res)=>{ - alert('Saved'); + this.presentToast(); },(err)=>{ console.log(err); }); @@ -125,4 +128,14 @@ export class SettingsPage implements OnInit { updateInterestsLocally(newSelectedInterests: string[]){ this.interestsSelected = newSelectedInterests; } + + async presentToast() { + const toast = await this.toastController.create({ + position: 'top', + message: 'Settings have been changed.', + duration: 2000 + }); + toast.present(); + } + }