added personal stream

This commit is contained in:
Morgan McMillian 2017-06-10 08:24:38 -07:00
parent 1c47be7675
commit 0a5c0fbab5
3 changed files with 34 additions and 9 deletions

View file

@ -19,15 +19,16 @@ export class MyApp {
rootPage: any = LoginPage;
pages: Array<{title: string, component: any}>;
pages: Array<{title: string, component: any, params: Object}>;
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, private storage: Storage) {
this.initializeApp();
// used for an example of ngFor and navigation
this.pages = [
{ title: 'Global Stream', component: StreamPage },
{ title: 'List', component: ListPage },
{ title: 'Global Stream', component: StreamPage, params: {stream: 'global'} },
{ title: 'Personal Stream', component: StreamPage, params: {stream: 'personal'} },
{ title: 'List', component: ListPage , params: {}},
];
}
@ -37,7 +38,7 @@ export class MyApp {
this.storage.get('token').then((val) => {
if (val.length > 1) {
pnut.token = val;
this.nav.setRoot(StreamPage);
this.nav.setRoot(StreamPage, {stream: 'global'});
}
}).catch(err => {
console.log('ERROR: ' + err);
@ -54,7 +55,7 @@ export class MyApp {
openPage(page) {
// Reset the content nav to have just this page
// we wouldn't want the back button to show in this scenario
this.nav.setRoot(page.component);
this.nav.setRoot(page.component, page.params);
}
}

View file

@ -7,7 +7,10 @@
<ion-header>
<ion-navbar>
<ion-title>stream</ion-title>
<button ion-button menuToggle>
<ion-icon name="menu"></ion-icon>
</button>
<ion-title>{{title}}</ion-title>
</ion-navbar>
</ion-header>
@ -21,7 +24,7 @@
<img src="{{post.user.content.avatar_image.link}}">
</ion-avatar>
<h2>{{ post.user.username }}</h2>
<p>{{post.content.text}}</p>
<p>{{ post.is_deleted ? '{post deleted}' : post.content.text }}</p>
</ion-item>
</ion-list>

View file

@ -16,10 +16,21 @@ import * as pnut from 'pnut-butter';
})
export class StreamPage {
title: string;
posts: Array<Object> = []
constructor(public navCtrl: NavController, public navParams: NavParams) {
// console.log(JSON.stringify(navParams));
switch (navParams.data.stream) {
case 'global':
this.title = 'Global';
this.fetchGlobal();
break;
case 'personal':
this.title = 'Home';
this.fetchPersonal();
break;
}
}
fetchGlobal() {
@ -27,6 +38,16 @@ export class StreamPage {
pnut.global().then(res => {
// console.log(res);
this.posts = res.data;
// console.log(this.posts);
}).catch(err => {
console.log(err);
});
}
fetchPersonal() {
console.log('-- fetching personal stream --');
pnut.personal().then(res => {
this.posts = res.data;
}).catch(err => {
console.log(err);
});