Skip to content

Commit

Permalink
Step 5.19: Create ProfileComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored and DAB0mB committed Dec 17, 2016
1 parent 37c9eef commit 1f086ce
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions client/imports/pages/auth/profile.component.ts
@@ -0,0 +1,55 @@
import {Component, OnInit} from '@angular/core';
import {NavController, AlertController} from 'ionic-angular';
import {Meteor} from 'meteor/meteor';
import {MeteorObservable} from 'meteor-rxjs';
import {Profile} from '../../../../both/models/profile.model';
import {TabsContainerComponent} from '../tabs-container/tabs-container.component';

import template from './profile.component.html';
import style from './profile.component.scss';

@Component({
selector: 'profile',
template,
styles: [
style
]
})
export class ProfileComponent implements OnInit {
profile: Profile;

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

ngOnInit(): void {
this.profile = Meteor.user().profile || {
name: '',
picture: '/assets/ionicons/dist/svg/ios-contact.svg'
};
}

done(): void {
MeteorObservable.call('updateProfile', this.profile).subscribe({
next: () => {
this.navCtrl.push(TabsContainerComponent);
},
error(e: Error) {
this.handleError(e);
}
});
}

private 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 1f086ce

Please sign in to comment.