Skip to content

Commit

Permalink
Step 17.11: Create FacebookPage
Browse files Browse the repository at this point in the history
  • Loading branch information
darkbasic committed Oct 16, 2017
1 parent f402102 commit 2c57869
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/pages/login/facebook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Component } from "@angular/core";
import { Alert, AlertController, NavController } from "ionic-angular";
import { PhoneService } from "../../services/phone";
import { ProfilePage } from "../profile/profile";

@Component({
selector: 'facebook',
templateUrl: 'facebook.html'
})
export class FacebookPage {

constructor(private alertCtrl: AlertController,
private phoneService: PhoneService,
private navCtrl: NavController) {
}

cancel(): void {
const alert: Alert = this.alertCtrl.create({
title: 'Confirm',
message: `Would you like to proceed without linking your account with Facebook?`,
buttons: [
{
text: 'Cancel',
role: 'cancel'
},
{
text: 'Yes',
handler: () => {
this.dontLink(alert);
return false;
}
}
]
});

alert.present();
}

linkFacebook(): void {
this.phoneService.linkFacebook()
.then(() => {
this.navCtrl.setRoot(ProfilePage, {}, {
animate: true
});
})
.catch((e) => {
this.handleError(e);
});
}

dontLink(alert: Alert): void {
alert.dismiss()
.then(() => {
this.navCtrl.setRoot(ProfilePage, {}, {
animate: true
});
})
.catch((e) => {
this.handleError(e);
});
}

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 2c57869

Please sign in to comment.