added personal stream
This commit is contained in:
parent
1c47be7675
commit
0a5c0fbab5
3 changed files with 34 additions and 9 deletions
|
@ -19,15 +19,16 @@ export class MyApp {
|
||||||
|
|
||||||
rootPage: any = LoginPage;
|
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) {
|
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, private storage: Storage) {
|
||||||
this.initializeApp();
|
this.initializeApp();
|
||||||
|
|
||||||
// used for an example of ngFor and navigation
|
// used for an example of ngFor and navigation
|
||||||
this.pages = [
|
this.pages = [
|
||||||
{ title: 'Global Stream', component: StreamPage },
|
{ title: 'Global Stream', component: StreamPage, params: {stream: 'global'} },
|
||||||
{ title: 'List', component: ListPage },
|
{ 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) => {
|
this.storage.get('token').then((val) => {
|
||||||
if (val.length > 1) {
|
if (val.length > 1) {
|
||||||
pnut.token = val;
|
pnut.token = val;
|
||||||
this.nav.setRoot(StreamPage);
|
this.nav.setRoot(StreamPage, {stream: 'global'});
|
||||||
}
|
}
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.log('ERROR: ' + err);
|
console.log('ERROR: ' + err);
|
||||||
|
@ -54,7 +55,7 @@ export class MyApp {
|
||||||
openPage(page) {
|
openPage(page) {
|
||||||
// Reset the content nav to have just this page
|
// Reset the content nav to have just this page
|
||||||
// we wouldn't want the back button to show in this scenario
|
// we wouldn't want the back button to show in this scenario
|
||||||
this.nav.setRoot(page.component);
|
this.nav.setRoot(page.component, page.params);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,10 @@
|
||||||
<ion-header>
|
<ion-header>
|
||||||
|
|
||||||
<ion-navbar>
|
<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-navbar>
|
||||||
|
|
||||||
</ion-header>
|
</ion-header>
|
||||||
|
@ -21,7 +24,7 @@
|
||||||
<img src="{{post.user.content.avatar_image.link}}">
|
<img src="{{post.user.content.avatar_image.link}}">
|
||||||
</ion-avatar>
|
</ion-avatar>
|
||||||
<h2>{{ post.user.username }}</h2>
|
<h2>{{ post.user.username }}</h2>
|
||||||
<p>{{post.content.text}}</p>
|
<p>{{ post.is_deleted ? '{post deleted}' : post.content.text }}</p>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
</ion-list>
|
</ion-list>
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,21 @@ import * as pnut from 'pnut-butter';
|
||||||
})
|
})
|
||||||
export class StreamPage {
|
export class StreamPage {
|
||||||
|
|
||||||
|
title: string;
|
||||||
posts: Array<Object> = []
|
posts: Array<Object> = []
|
||||||
|
|
||||||
constructor(public navCtrl: NavController, public navParams: NavParams) {
|
constructor(public navCtrl: NavController, public navParams: NavParams) {
|
||||||
|
// console.log(JSON.stringify(navParams));
|
||||||
|
switch (navParams.data.stream) {
|
||||||
|
case 'global':
|
||||||
|
this.title = 'Global';
|
||||||
this.fetchGlobal();
|
this.fetchGlobal();
|
||||||
|
break;
|
||||||
|
case 'personal':
|
||||||
|
this.title = 'Home';
|
||||||
|
this.fetchPersonal();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchGlobal() {
|
fetchGlobal() {
|
||||||
|
@ -27,6 +38,16 @@ export class StreamPage {
|
||||||
pnut.global().then(res => {
|
pnut.global().then(res => {
|
||||||
// console.log(res);
|
// console.log(res);
|
||||||
this.posts = res.data;
|
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 => {
|
}).catch(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue