Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 5.30: Add chats-options component
- Loading branch information
1 parent
a7011ca
commit dc4f46d
Showing
1 changed file
with
72 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,72 @@ | ||
import { Component } from '@angular/core'; | ||
import { NavController, ViewController, AlertController } from 'ionic-angular'; | ||
import { ProfileComponent } from '../profile/profile'; | ||
import { LoginComponent } from '../auth/login'; | ||
|
||
declare let Meteor; | ||
|
||
@Component({ | ||
selector: 'chats-options', | ||
templateUrl: 'chat-options.html' | ||
}) | ||
export class ChatsOptionsComponent { | ||
constructor( | ||
public navCtrl: NavController, | ||
public viewCtrl: ViewController, | ||
public 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(); | ||
} | ||
} |