From 9e540f774bc7ae7ef01f089d1ae8312b635ca567 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Tue, 20 Nov 2018 14:38:29 -0800 Subject: [PATCH] add user profile to main menu --- src/app/app.component.ts | 14 +++++++++++--- src/pages/profile/profile-menu.ts | 6 ++++-- src/pages/profile/profile.html | 2 +- src/pages/profile/profile.ts | 16 +++++++++++++--- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 38d60e4..4c4144a 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -8,6 +8,9 @@ import { LoginPage } from '../pages/login/login'; import { StreamPage } from '../pages/stream/stream'; import { SettingsPage } from '../pages/settings/settings'; import { AboutPage } from '../pages/about/about'; +import { ProfilePage } from '../pages/profile/profile'; + +import { IUser } from '../models/IUser'; import * as pnut from 'pnut-butter'; @@ -18,10 +21,9 @@ export class MyApp { @ViewChild(Nav) nav: Nav; rootPage: any = StreamPage; - pages: Array<{title: string, icon: string, component: any, params: Object}>; - scope: Array = ['basic','stream','write_post','files']; + profile: IUser; constructor(public platform: Platform, public splashScreen: SplashScreen, private storage: Storage, private device: Device) { @@ -33,6 +35,7 @@ export class MyApp { { title: 'Mentions', icon: 'at', component: StreamPage, params: {stream: 'mentions'} }, { title: 'Global', icon: 'globe', component: StreamPage, params: {stream: 'global'} }, { title: 'Bookmarks', icon: 'bookmarks', component: StreamPage, params: {stream: 'bookmarks'} }, + { title: 'Profile', icon: 'person', component: ProfilePage, params: {}}, { title: 'Settings', icon: 'settings', component: SettingsPage, params: {}}, { title: 'About', icon: 'information-circle', component: AboutPage, params: {}}, { title: 'Logout', icon: 'exit', component: {}, params: {}}, @@ -43,7 +46,6 @@ export class MyApp { initializeApp() { console.log('--- initializeApp ---'); - this.platform.ready().then(() => { // Okay, so the platform is ready and our plugins are available. // Here you can do any higher level native things you might need. @@ -81,6 +83,9 @@ export class MyApp { this.nav.setRoot(LoginPage, {'scope': this.scope}); }); // this.nav.setRoot(StreamPage, {stream: timeline}); + pnut.user('me').then(res => { + this.profile = res.data as IUser; + }); } }).catch(err => { console.log('ERROR: ' + err); @@ -97,6 +102,9 @@ export class MyApp { this.nav.setRoot(LoginPage, {'scope': this.scope}); } else if (page.title === 'Settings' || page.title === 'About') { this.nav.push(page.component, page.params); + } else if (page.title === 'Profile') { + page.params = {user: this.profile, me: this.profile.username}; + this.nav.push(page.component, page.params); } else { this.nav.setRoot(page.component, page.params); } diff --git a/src/pages/profile/profile-menu.ts b/src/pages/profile/profile-menu.ts index 3abd9d6..14d4133 100644 --- a/src/pages/profile/profile-menu.ts +++ b/src/pages/profile/profile-menu.ts @@ -8,8 +8,8 @@ import * as pnut from 'pnut-butter'; template: ` - - + + ` }) @@ -19,6 +19,7 @@ export class ProfileMenu { private username: string; private you_muted: boolean; private you_blocked: boolean; + private myUsername: string; constructor(public navParams: NavParams, public viewCtrl: ViewController, public toastCtrl: ToastController, public events: Events) { @@ -26,6 +27,7 @@ export class ProfileMenu { this.username = this.navParams.data.username; this.you_muted = this.navParams.data.you_muted; this.you_blocked = this.navParams.data.you_blocked; + this.myUsername = this.navParams.data.me; } browse() { diff --git a/src/pages/profile/profile.html b/src/pages/profile/profile.html index b76470a..c656089 100644 --- a/src/pages/profile/profile.html +++ b/src/pages/profile/profile.html @@ -29,7 +29,7 @@

{{ user.name }}

@{{ user.username }}

- + {{ user.follows_you ? "Follows you" : ""}} diff --git a/src/pages/profile/profile.ts b/src/pages/profile/profile.ts index 057eb23..76fc70b 100644 --- a/src/pages/profile/profile.ts +++ b/src/pages/profile/profile.ts @@ -3,6 +3,8 @@ import { NavController, NavParams, PopoverController, ToastController } from 'io import { UserListPage } from '../user-list/user-list'; import { ProfileMenu } from './profile-menu' +import { IUser } from '../../models/IUser'; + import * as pnut from 'pnut-butter'; /** @@ -18,7 +20,7 @@ import * as pnut from 'pnut-butter'; }) export class ProfilePage { - private user: any; + private user: IUser; private posts: Array = []; private bookmarks: Array = []; private before_id_post: string; @@ -28,8 +30,15 @@ export class ProfilePage { constructor(public navCtrl: NavController, public navParams: NavParams, public popoverCtrl: PopoverController, public toastCtrl: ToastController) { - this.user = this.navParams.data.user; - this.myUsername = this.navParams.data.me; + + if (this.navParams.data.user) { + this.user = this.navParams.data.user; + this.myUsername = this.navParams.data.me; + console.log('user: ' + this.user.username); + console.log('me: ' + this.myUsername); + } else { + console.log('err, I need user data!!!'); + } } ionViewDidLoad() { @@ -130,6 +139,7 @@ export class ProfilePage { presentProfileMenu(myEvent) { let popover = this.popoverCtrl.create(ProfileMenu, { + me: this.myUsername, userid: this.user.id, username: this.user.username, you_muted: this.user.you_muted,