Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 5.29: Add ChatsOptionsComponent
- Loading branch information
1 parent
773d266
commit 1636b58
Showing
1 changed file
with
76 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,76 @@ | ||
import {Component} from '@angular/core'; | ||
import {NavController, ViewController, AlertController} from 'ionic-angular'; | ||
import {Meteor} from 'meteor/meteor'; | ||
import {ProfileComponent} from '../auth/profile.component'; | ||
import {LoginComponent} from '../auth/login.component'; | ||
import template from './chats-options.component.html'; | ||
import style from "./chats-options.component.scss"; | ||
|
||
@Component({ | ||
selector: 'chats-options', | ||
template, | ||
styles: [ | ||
style | ||
] | ||
}) | ||
export class ChatsOptionsComponent { | ||
constructor( | ||
private navCtrl: NavController, | ||
private viewCtrl: ViewController, | ||
private alertCtrl: AlertController | ||
) {} | ||
|
||
editProfile(): void { | ||
this.viewCtrl.dismiss().then(() => { | ||
this.navCtrl.push(ProfileComponent); | ||
}); | ||
} | ||
|
||
logout(): void { | ||
const alert = this.alertCtrl.create({ | ||
title: 'Logout', | ||
message: 'Are you sure you would like to proceed?', | ||
buttons: [ | ||
{ | ||
text: 'Cancel', | ||
role: 'cancel' | ||
}, | ||
{ | ||
text: 'Yes', | ||
handler: () => { | ||
this.handleLogout(alert); | ||
return false; | ||
} | ||
} | ||
] | ||
}); | ||
|
||
this.viewCtrl.dismiss().then(() => { | ||
alert.present(); | ||
}); | ||
} | ||
|
||
private handleLogout(alert): void { | ||
Meteor.logout((e: Error) => { | ||
alert.dismiss().then(() => { | ||
if (e) return this.handleError(e); | ||
|
||
this.navCtrl.setRoot(LoginComponent, {}, { | ||
animate: true | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
private handleError(e: Error): void { | ||
console.error(e); | ||
|
||
const alert = this.alertCtrl.create({ | ||
title: 'Oops!', | ||
message: e.message, | ||
buttons: ['OK'] | ||
}); | ||
|
||
alert.present(); | ||
} | ||
} |