Skip to content

Commit 897966b

Browse files
dotansimhadarkbasic
authored andcommitted
Step 9.4: Add message options component
1 parent 77521b2 commit 897966b

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Component } from '@angular/core';
2+
import { AlertController, NavController, NavParams, ViewController } from 'ionic-angular';
3+
import { MeteorObservable } from 'meteor-rxjs';
4+
import { ChatsPage } from '../chats/chats';
5+
6+
@Component({
7+
selector: 'messages-options',
8+
templateUrl: 'messages-options.html'
9+
})
10+
export class MessagesOptionsComponent {
11+
constructor(
12+
public alertCtrl: AlertController,
13+
public navCtrl: NavController,
14+
public params: NavParams,
15+
public viewCtrl: ViewController
16+
) {}
17+
18+
remove(): void {
19+
const alert = this.alertCtrl.create({
20+
title: 'Remove',
21+
message: 'Are you sure you would like to proceed?',
22+
buttons: [
23+
{
24+
text: 'Cancel',
25+
role: 'cancel'
26+
},
27+
{
28+
text: 'Yes',
29+
handler: () => {
30+
this.handleRemove(alert);
31+
return false;
32+
}
33+
}
34+
]
35+
});
36+
37+
this.viewCtrl.dismiss().then(() => {
38+
alert.present();
39+
});
40+
}
41+
42+
private handleRemove(alert): void {
43+
MeteorObservable.call('removeChat', this.params.get('chat')._id).subscribe({
44+
next: () => {
45+
alert.dismiss().then(() => {
46+
this.navCtrl.setRoot(ChatsPage, {}, {
47+
animate: true
48+
});
49+
});
50+
},
51+
error: (e: Error) => {
52+
alert.dismiss().then(() => {
53+
if (e) {
54+
return this.handleError(e);
55+
}
56+
57+
this.navCtrl.setRoot(ChatsPage, {}, {
58+
animate: true
59+
});
60+
});
61+
}
62+
});
63+
}
64+
65+
private handleError(e: Error): void {
66+
console.error(e);
67+
68+
const alert = this.alertCtrl.create({
69+
title: 'Oops!',
70+
message: e.message,
71+
buttons: ['OK']
72+
});
73+
74+
alert.present();
75+
}
76+
}

0 commit comments

Comments
 (0)