Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Step 5.28: Add ChatsOptionsComponent
  • Loading branch information
kamilkisiela authored and dotansimha committed Nov 27, 2016
1 parent 8f92b2f commit c4f0343
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions client/imports/pages/chats/chats-options.component.ts
@@ -0,0 +1,76 @@
import {Component} from '@angular/core';
import {NavController, ViewController, AlertController} from 'ionic-angular';
import {Meteor} from 'meteor/meteor';
import {ProfileComponent} from '../auth/profile.component';
import {LoginComponent} from '../auth/login.component';
import template from './chats-options.component.html';
import style from "./chats-options.component.scss";

@Component({
selector: 'chats-options',
template,
styles: [
style
]
})
export class ChatsOptionsComponent {
constructor(
private navCtrl: NavController,
private viewCtrl: ViewController,
private 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 c4f0343

Please sign in to comment.