Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 7.3: Create MessagesOptionsComponent
- Loading branch information
1 parent
f9cfc14
commit d9c0eb9
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import {Component} from '@angular/core'; | ||
import {NavParams, NavController, ViewController, AlertController} from 'ionic-angular'; | ||
import {Meteor} from 'meteor/meteor'; | ||
import {MeteorObservable} from 'meteor-rxjs'; | ||
import template from './messages-options.component.html'; | ||
import style from "./messages-options.component.scss"; | ||
import {TabsContainerComponent} from '../tabs-container/tabs-container.component'; | ||
|
||
@Component({ | ||
selector: 'messages-options', | ||
template, | ||
styles: [ | ||
style | ||
] | ||
}) | ||
export class MessagesOptionsComponent { | ||
constructor( | ||
private navCtrl: NavController, | ||
private viewCtrl: ViewController, | ||
private alertCtrl: AlertController, | ||
private 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(TabsContainerComponent, {}, { | ||
animate: true | ||
}); | ||
}); | ||
}, | ||
error: (e: Error) => { | ||
alert.dismiss().then(() => { | ||
if (e) return this.handleError(e); | ||
|
||
this.navCtrl.setRoot(TabsContainerComponent, {}, { | ||
animate: true | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
private handleError(e: Error): void { | ||
console.error(e); | ||
|
||
const alert = this.alertCtrl.create({ | ||
title: 'Oops!', | ||
message: e.message, | ||
buttons: ['OK'] | ||
}); | ||
|
||
alert.present(); | ||
} | ||
} |