From 5a4cc57772add90f9e568be44e817a5902645dea Mon Sep 17 00:00:00 2001 From: dotansimha Date: Tue, 24 Jan 2017 16:55:20 +0200 Subject: [PATCH] Step 7.23: Add profile component --- src/pages/profile/profile.ts | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/pages/profile/profile.ts diff --git a/src/pages/profile/profile.ts b/src/pages/profile/profile.ts new file mode 100644 index 000000000..dbd14aa39 --- /dev/null +++ b/src/pages/profile/profile.ts @@ -0,0 +1,48 @@ +import { Component, OnInit } from '@angular/core'; +import { Profile } from 'api/models'; +import { AlertController, NavController } from 'ionic-angular'; +import { MeteorObservable } from 'meteor-rxjs'; +import { ChatsPage } from '../chats/chats'; + +@Component({ + selector: 'profile', + templateUrl: 'profile.html' +}) +export class ProfilePage implements OnInit { + picture: string; + profile: Profile; + + constructor( + private alertCtrl: AlertController, + private navCtrl: NavController + ) {} + + ngOnInit(): void { + this.profile = Meteor.user().profile || { + name: '' + }; + } + + updateProfile(): void { + MeteorObservable.call('updateProfile', this.profile).subscribe({ + next: () => { + this.navCtrl.push(ChatsPage); + }, + error: (e: Error) => { + this.handleError(e); + } + }); + } + + handleError(e: Error): void { + console.error(e); + + const alert = this.alertCtrl.create({ + title: 'Oops!', + message: e.message, + buttons: ['OK'] + }); + + alert.present(); + } +}