diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 4bb6a8d..0b26f20 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -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); } } diff --git a/src/pages/stream/stream.html b/src/pages/stream/stream.html index 45904bc..1002ea9 100644 --- a/src/pages/stream/stream.html +++ b/src/pages/stream/stream.html @@ -7,7 +7,10 @@ - stream + + {{title}} @@ -20,8 +23,8 @@ -

{{post.user.username}}

-

{{post.content.text}}

+

{{ post.user.username }}

+

{{ post.is_deleted ? '{post deleted}' : post.content.text }}

diff --git a/src/pages/stream/stream.ts b/src/pages/stream/stream.ts index e250aca..7feb046 100644 --- a/src/pages/stream/stream.ts +++ b/src/pages/stream/stream.ts @@ -16,10 +16,21 @@ import * as pnut from 'pnut-butter'; }) export class StreamPage { + title: string; posts: Array = [] constructor(public navCtrl: NavController, public navParams: NavParams) { - this.fetchGlobal(); + // 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); });