Permalink
Browse files

Step 9.4: Add message options component

  • Loading branch information...
dotansimha authored and darkbasic committed Jan 24, 2017
1 parent 77521b2 commit 897966bee50d0814a3d0b96556605b378014346d
Showing with 76 additions and 0 deletions.
  1. +76 −0 src/pages/messages/messages-options.ts
@@ -0,0 +1,76 @@
import { Component } from '@angular/core';
import { AlertController, NavController, NavParams, ViewController } from 'ionic-angular';
import { MeteorObservable } from 'meteor-rxjs';
import { ChatsPage } from '../chats/chats';
@Component({
selector: 'messages-options',
templateUrl: 'messages-options.html'
})
export class MessagesOptionsComponent {
constructor(
public alertCtrl: AlertController,
public navCtrl: NavController,
public params: NavParams,
public viewCtrl: ViewController
) {}
remove(): void {
const alert = this.alertCtrl.create({
title: 'Remove',
message: 'Are you sure you would like to proceed?',
buttons: [
{
text: 'Cancel',
role: 'cancel'
},
{
text: 'Yes',
handler: () => {
this.handleRemove(alert);
return false;
}
}
]
});
this.viewCtrl.dismiss().then(() => {
alert.present();
});
}
private handleRemove(alert): void {
MeteorObservable.call('removeChat', this.params.get('chat')._id).subscribe({
next: () => {
alert.dismiss().then(() => {
this.navCtrl.setRoot(ChatsPage, {}, {
animate: true
});
});
},
error: (e: Error) => {
alert.dismiss().then(() => {
if (e) {
return this.handleError(e);
}
this.navCtrl.setRoot(ChatsPage, {}, {
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 897966b

Please sign in to comment.