Skip to content

Commit

Permalink
Step 7.3: Create MessagesOptionsComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Dec 24, 2016
1 parent 51d7707 commit d9ffc21
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions 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 d9ffc21

Please sign in to comment.