Skip to content

Commit

Permalink
Step 12.24: Implement pick, update and set of profile image
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha authored and DAB0mB committed Mar 23, 2017
1 parent 131dec0 commit 78c536a
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/pages/profile/profile.ts
Expand Up @@ -3,6 +3,8 @@ import { Profile } from 'api/models';
import { AlertController, NavController } from 'ionic-angular';
import { MeteorObservable } from 'meteor-rxjs';
import { ChatsPage } from '../chats/chats';
import { PictureService } from '../../services/picture';
import { Pictures } from 'api/collections';

@Component({
selector: 'profile',
Expand All @@ -14,13 +16,37 @@ export class ProfilePage implements OnInit {

constructor(
private alertCtrl: AlertController,
private navCtrl: NavController
private navCtrl: NavController,
private pictureService: PictureService
) {}

ngOnInit(): void {
this.profile = Meteor.user().profile || {
name: ''
};

MeteorObservable.subscribe('user').subscribe(() => {
this.picture = Pictures.getPictureUrl(this.profile.pictureId);
});
}

selectProfilePicture(): void {
this.pictureService.select().then((blob) => {
this.uploadProfilePicture(blob);
})
.catch((e) => {
this.handleError(e);
});
}

uploadProfilePicture(blob: Blob): void {
this.pictureService.upload(blob).then((picture) => {
this.profile.pictureId = picture._id;
this.picture = picture.url;
})
.catch((e) => {
this.handleError(e);
});
}

updateProfile(): void {
Expand Down

0 comments on commit 78c536a

Please sign in to comment.