Skip to content

Commit

Permalink
Step 17.19: Update facebook.ts to set name and picture from Facebook
Browse files Browse the repository at this point in the history
  • Loading branch information
darkbasic committed Jun 15, 2017
1 parent bc48978 commit 187a918
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/pages/login/facebook.ts
Expand Up @@ -2,6 +2,9 @@ import { Component } from "@angular/core";
import { Alert, AlertController, NavController } from "ionic-angular";
import { PhoneService } from "../../services/phone";
import { ProfilePage } from "../profile/profile";
import { MeteorObservable } from "meteor-rxjs";
import { FbProfile } from "api/services/facebook";
import { Profile } from "api/models";

@Component({
selector: 'facebook',
Expand Down Expand Up @@ -39,8 +42,29 @@ export class FacebookPage {
linkFacebook(): void {
this.phoneService.linkFacebook()
.then(() => {
this.navCtrl.setRoot(ProfilePage, {}, {
animate: true
MeteorObservable.call('getFbProfile').subscribe({
next: (fbProfile: FbProfile) => {
const pathname = (new URL(fbProfile.pictureUrl)).pathname;
const filename = pathname.substring(pathname.lastIndexOf('/') + 1);
const description = {name: filename};
let profile: Profile = {name: fbProfile.name, pictureId: ""};
MeteorObservable.call('ufsImportURL', fbProfile.pictureUrl, description, 'pictures')
.map((value) => profile.pictureId = (<any>value)._id)
.switchMapTo(MeteorObservable.call('updateProfile', profile))
.subscribe({
next: () => {
this.navCtrl.setRoot(ProfilePage, {}, {
animate: true
});
},
error: (e: Error) => {
this.handleError(e);
}
});
},
error: (e: Error) => {
this.handleError(e);
}
});
})
.catch((e) => {
Expand Down

0 comments on commit 187a918

Please sign in to comment.