Permalink
Browse files

Step 7.32: Add chat options component

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 24, 2017
1 parent 885af27 commit 43ea7cf56d0472c48b04b32220782d894a875150
Showing with 75 additions and 0 deletions.
  1. +75 −0 src/pages/chats/chats-options.ts
@@ -0,0 +1,75 @@
import { Component, Injectable } from '@angular/core';
import { Alert, AlertController, NavController, ViewController } from 'ionic-angular';
import { PhoneService } from '../../services/phone';
import { LoginPage } from '../login/login';
import { ProfilePage } from '../profile/profile';
@Component({
selector: 'chats-options',
templateUrl: 'chats-options.html'
})
@Injectable()
export class ChatsOptionsComponent {
constructor(
private alertCtrl: AlertController,
private navCtrl: NavController,
private phoneService: PhoneService,
private viewCtrl: ViewController
) {}
editProfile(): void {
this.viewCtrl.dismiss().then(() => {
this.navCtrl.push(ProfilePage);
});
}
logout(): void {
const alert = this.alertCtrl.create({
title: 'Logout',
message: 'Are you sure you would like to proceed?',
buttons: [
{
text: 'Cancel',
role: 'cancel'
},
{
text: 'Yes',
handler: () => {
this.handleLogout(alert);
return false;
}
}
]
});
this.viewCtrl.dismiss().then(() => {
alert.present();
});
}
handleLogout(alert: Alert): void {
alert.dismiss().then(() => {
return this.phoneService.logout();
})
.then(() => {
this.navCtrl.setRoot(LoginPage, {}, {
animate: true
});
})
.catch((e) => {
this.handleError(e);
});
}
handleError(e: Error): void {
console.error(e);
const alert = this.alertCtrl.create({
title: 'Oops!',
message: e.message,
buttons: ['OK']
});
alert.present();
}
}

0 comments on commit 43ea7cf

Please sign in to comment.