Skip to content

Commit 5a4cc57

Browse files
dotansimhadarkbasic
authored andcommitted
Step 7.23: Add profile component
1 parent e9aba64 commit 5a4cc57

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/pages/profile/profile.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { Profile } from 'api/models';
3+
import { AlertController, NavController } from 'ionic-angular';
4+
import { MeteorObservable } from 'meteor-rxjs';
5+
import { ChatsPage } from '../chats/chats';
6+
7+
@Component({
8+
selector: 'profile',
9+
templateUrl: 'profile.html'
10+
})
11+
export class ProfilePage implements OnInit {
12+
picture: string;
13+
profile: Profile;
14+
15+
constructor(
16+
private alertCtrl: AlertController,
17+
private navCtrl: NavController
18+
) {}
19+
20+
ngOnInit(): void {
21+
this.profile = Meteor.user().profile || {
22+
name: ''
23+
};
24+
}
25+
26+
updateProfile(): void {
27+
MeteorObservable.call('updateProfile', this.profile).subscribe({
28+
next: () => {
29+
this.navCtrl.push(ChatsPage);
30+
},
31+
error: (e: Error) => {
32+
this.handleError(e);
33+
}
34+
});
35+
}
36+
37+
handleError(e: Error): void {
38+
console.error(e);
39+
40+
const alert = this.alertCtrl.create({
41+
title: 'Oops!',
42+
message: e.message,
43+
buttons: ['OK']
44+
});
45+
46+
alert.present();
47+
}
48+
}

0 commit comments

Comments
 (0)