Skip to content

Commit

Permalink
Step 5.31: Add chats-options component
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Dec 24, 2016
1 parent 9d567e8 commit 9c913f2
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/pages/chat-options/chat-options.ts
@@ -0,0 +1,70 @@
import { Component } from '@angular/core';
import { NavController, ViewController, AlertController } from 'ionic-angular';
import { ProfileComponent } from '../profile/profile';
import { LoginComponent } from '../auth/login';

@Component({
selector: 'chats-options',
templateUrl: 'chat-options.html'
})
export class ChatsOptionsComponent {
constructor(
public navCtrl: NavController,
public viewCtrl: ViewController,
public alertCtrl: AlertController
) {}

editProfile(): void {
this.viewCtrl.dismiss().then(() => {
this.navCtrl.push(ProfileComponent);
});
}

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();
});
}

private handleLogout(alert): void {
Meteor.logout((e: Error) => {
alert.dismiss().then(() => {
if (e) return this.handleError(e);

this.navCtrl.setRoot(LoginComponent, {}, {
animate: true
});
});
});
}

private 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 9c913f2

Please sign in to comment.