add user profile to main menu

This commit is contained in:
Morgan McMillian 2018-11-20 14:38:29 -08:00
parent da9a3a801a
commit 9e540f774b
4 changed files with 29 additions and 9 deletions

View file

@ -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<string> = ['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);
}

View file

@ -8,8 +8,8 @@ import * as pnut from 'pnut-butter';
template: `
<ion-list>
<button ion-item (click)="browse()">Open in browser</button>
<button ion-item >Block</button>
<button ion-item >Mute</button>
<button ion-item [disabled]="myUsername == username">Block</button>
<button ion-item [disabled]="myUsername == username">Mute</button>
</ion-list>
`
})
@ -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() {

View file

@ -29,7 +29,7 @@
<h2>{{ user.name }}</h2>
<p>@{{ user.username }}</p>
<ion-col item-end text-right>
<button ion-button (click)="followUser()">{{ user.you_follow ? "Unfollow" : "Follow" }}</button>
<button ion-button [disabled]="myUsername == user.username" (click)="followUser()">{{ user.you_follow ? "Unfollow" : "Follow" }}</button>
<ion-note>{{ user.follows_you ? "Follows you" : ""}}</ion-note>
</ion-col>
</ion-item>

View file

@ -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<Object> = [];
private bookmarks: Array<Object> = [];
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,