Skip to content
Permalink
Browse files

Step 7.3: Create MessagesOptionsComponent

  • Loading branch information...
dotansimha authored and DAB0mB committed Nov 3, 2016
1 parent e06df6f commit 78129166810805fd91a7a3bec052d35b11bcc6ec
Showing with 74 additions and 0 deletions.
  1. +74 −0 src/pages/messages-options/messages-options.ts
@@ -0,0 +1,74 @@
import { Component } from '@angular/core';
import { NavParams, NavController, ViewController, AlertController } from 'ionic-angular';
import { MeteorObservable } from 'meteor-rxjs';
import { TabsPage } from "../tabs/tabs";

@Component({
selector: 'messages-options',
templateUrl: 'messages-options.html'
})
export class MessagesOptionsComponent {
constructor(
public navCtrl: NavController,
public viewCtrl: ViewController,
public alertCtrl: AlertController,
public params: NavParams
) {}

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(TabsPage, {}, {
animate: true
});
});
},
error: (e: Error) => {
alert.dismiss().then(() => {
if (e) return this.handleError(e);

this.navCtrl.setRoot(TabsPage, {}, {
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 7812916

Please sign in to comment.
You can’t perform that action at this time.