add user profile to main menu
This commit is contained in:
parent
da9a3a801a
commit
9e540f774b
4 changed files with 29 additions and 9 deletions
|
@ -8,6 +8,9 @@ import { LoginPage } from '../pages/login/login';
|
||||||
import { StreamPage } from '../pages/stream/stream';
|
import { StreamPage } from '../pages/stream/stream';
|
||||||
import { SettingsPage } from '../pages/settings/settings';
|
import { SettingsPage } from '../pages/settings/settings';
|
||||||
import { AboutPage } from '../pages/about/about';
|
import { AboutPage } from '../pages/about/about';
|
||||||
|
import { ProfilePage } from '../pages/profile/profile';
|
||||||
|
|
||||||
|
import { IUser } from '../models/IUser';
|
||||||
|
|
||||||
import * as pnut from 'pnut-butter';
|
import * as pnut from 'pnut-butter';
|
||||||
|
|
||||||
|
@ -18,10 +21,9 @@ export class MyApp {
|
||||||
@ViewChild(Nav) nav: Nav;
|
@ViewChild(Nav) nav: Nav;
|
||||||
|
|
||||||
rootPage: any = StreamPage;
|
rootPage: any = StreamPage;
|
||||||
|
|
||||||
pages: Array<{title: string, icon: string, component: any, params: Object}>;
|
pages: Array<{title: string, icon: string, component: any, params: Object}>;
|
||||||
|
|
||||||
scope: Array<string> = ['basic','stream','write_post','files'];
|
scope: Array<string> = ['basic','stream','write_post','files'];
|
||||||
|
profile: IUser;
|
||||||
|
|
||||||
constructor(public platform: Platform, public splashScreen: SplashScreen,
|
constructor(public platform: Platform, public splashScreen: SplashScreen,
|
||||||
private storage: Storage, private device: Device) {
|
private storage: Storage, private device: Device) {
|
||||||
|
@ -33,6 +35,7 @@ export class MyApp {
|
||||||
{ title: 'Mentions', icon: 'at', component: StreamPage, params: {stream: 'mentions'} },
|
{ title: 'Mentions', icon: 'at', component: StreamPage, params: {stream: 'mentions'} },
|
||||||
{ title: 'Global', icon: 'globe', component: StreamPage, params: {stream: 'global'} },
|
{ title: 'Global', icon: 'globe', component: StreamPage, params: {stream: 'global'} },
|
||||||
{ title: 'Bookmarks', icon: 'bookmarks', component: StreamPage, params: {stream: 'bookmarks'} },
|
{ title: 'Bookmarks', icon: 'bookmarks', component: StreamPage, params: {stream: 'bookmarks'} },
|
||||||
|
{ title: 'Profile', icon: 'person', component: ProfilePage, params: {}},
|
||||||
{ title: 'Settings', icon: 'settings', component: SettingsPage, params: {}},
|
{ title: 'Settings', icon: 'settings', component: SettingsPage, params: {}},
|
||||||
{ title: 'About', icon: 'information-circle', component: AboutPage, params: {}},
|
{ title: 'About', icon: 'information-circle', component: AboutPage, params: {}},
|
||||||
{ title: 'Logout', icon: 'exit', component: {}, params: {}},
|
{ title: 'Logout', icon: 'exit', component: {}, params: {}},
|
||||||
|
@ -43,7 +46,6 @@ export class MyApp {
|
||||||
initializeApp() {
|
initializeApp() {
|
||||||
console.log('--- initializeApp ---');
|
console.log('--- initializeApp ---');
|
||||||
|
|
||||||
|
|
||||||
this.platform.ready().then(() => {
|
this.platform.ready().then(() => {
|
||||||
// Okay, so the platform is ready and our plugins are available.
|
// Okay, so the platform is ready and our plugins are available.
|
||||||
// Here you can do any higher level native things you might need.
|
// 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(LoginPage, {'scope': this.scope});
|
||||||
});
|
});
|
||||||
// this.nav.setRoot(StreamPage, {stream: timeline});
|
// this.nav.setRoot(StreamPage, {stream: timeline});
|
||||||
|
pnut.user('me').then(res => {
|
||||||
|
this.profile = res.data as IUser;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log('ERROR: ' + err);
|
console.log('ERROR: ' + err);
|
||||||
|
@ -97,6 +102,9 @@ export class MyApp {
|
||||||
this.nav.setRoot(LoginPage, {'scope': this.scope});
|
this.nav.setRoot(LoginPage, {'scope': this.scope});
|
||||||
} else if (page.title === 'Settings' || page.title === 'About') {
|
} else if (page.title === 'Settings' || page.title === 'About') {
|
||||||
this.nav.push(page.component, page.params);
|
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 {
|
} else {
|
||||||
this.nav.setRoot(page.component, page.params);
|
this.nav.setRoot(page.component, page.params);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ import * as pnut from 'pnut-butter';
|
||||||
template: `
|
template: `
|
||||||
<ion-list>
|
<ion-list>
|
||||||
<button ion-item (click)="browse()">Open in browser</button>
|
<button ion-item (click)="browse()">Open in browser</button>
|
||||||
<button ion-item >Block</button>
|
<button ion-item [disabled]="myUsername == username">Block</button>
|
||||||
<button ion-item >Mute</button>
|
<button ion-item [disabled]="myUsername == username">Mute</button>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
|
@ -19,6 +19,7 @@ export class ProfileMenu {
|
||||||
private username: string;
|
private username: string;
|
||||||
private you_muted: boolean;
|
private you_muted: boolean;
|
||||||
private you_blocked: boolean;
|
private you_blocked: boolean;
|
||||||
|
private myUsername: string;
|
||||||
|
|
||||||
constructor(public navParams: NavParams, public viewCtrl: ViewController,
|
constructor(public navParams: NavParams, public viewCtrl: ViewController,
|
||||||
public toastCtrl: ToastController, public events: Events) {
|
public toastCtrl: ToastController, public events: Events) {
|
||||||
|
@ -26,6 +27,7 @@ export class ProfileMenu {
|
||||||
this.username = this.navParams.data.username;
|
this.username = this.navParams.data.username;
|
||||||
this.you_muted = this.navParams.data.you_muted;
|
this.you_muted = this.navParams.data.you_muted;
|
||||||
this.you_blocked = this.navParams.data.you_blocked;
|
this.you_blocked = this.navParams.data.you_blocked;
|
||||||
|
this.myUsername = this.navParams.data.me;
|
||||||
}
|
}
|
||||||
|
|
||||||
browse() {
|
browse() {
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<h2>{{ user.name }}</h2>
|
<h2>{{ user.name }}</h2>
|
||||||
<p>@{{ user.username }}</p>
|
<p>@{{ user.username }}</p>
|
||||||
<ion-col item-end text-right>
|
<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-note>{{ user.follows_you ? "Follows you" : ""}}</ion-note>
|
||||||
</ion-col>
|
</ion-col>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|
|
@ -3,6 +3,8 @@ import { NavController, NavParams, PopoverController, ToastController } from 'io
|
||||||
import { UserListPage } from '../user-list/user-list';
|
import { UserListPage } from '../user-list/user-list';
|
||||||
import { ProfileMenu } from './profile-menu'
|
import { ProfileMenu } from './profile-menu'
|
||||||
|
|
||||||
|
import { IUser } from '../../models/IUser';
|
||||||
|
|
||||||
import * as pnut from 'pnut-butter';
|
import * as pnut from 'pnut-butter';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,7 +20,7 @@ import * as pnut from 'pnut-butter';
|
||||||
})
|
})
|
||||||
export class ProfilePage {
|
export class ProfilePage {
|
||||||
|
|
||||||
private user: any;
|
private user: IUser;
|
||||||
private posts: Array<Object> = [];
|
private posts: Array<Object> = [];
|
||||||
private bookmarks: Array<Object> = [];
|
private bookmarks: Array<Object> = [];
|
||||||
private before_id_post: string;
|
private before_id_post: string;
|
||||||
|
@ -28,8 +30,15 @@ export class ProfilePage {
|
||||||
|
|
||||||
constructor(public navCtrl: NavController, public navParams: NavParams,
|
constructor(public navCtrl: NavController, public navParams: NavParams,
|
||||||
public popoverCtrl: PopoverController, public toastCtrl: ToastController) {
|
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() {
|
ionViewDidLoad() {
|
||||||
|
@ -130,6 +139,7 @@ export class ProfilePage {
|
||||||
|
|
||||||
presentProfileMenu(myEvent) {
|
presentProfileMenu(myEvent) {
|
||||||
let popover = this.popoverCtrl.create(ProfileMenu, {
|
let popover = this.popoverCtrl.create(ProfileMenu, {
|
||||||
|
me: this.myUsername,
|
||||||
userid: this.user.id,
|
userid: this.user.id,
|
||||||
username: this.user.username,
|
username: this.user.username,
|
||||||
you_muted: this.user.you_muted,
|
you_muted: this.user.you_muted,
|
||||||
|
|
Reference in a new issue