include mentions, bookmarks, and logout button
This commit is contained in:
parent
4bbff3cf8a
commit
cd65ed97cd
3 changed files with 50 additions and 11 deletions
|
@ -26,8 +26,11 @@ export class MyApp {
|
|||
|
||||
// used for an example of ngFor and navigation
|
||||
this.pages = [
|
||||
{ title: 'Personal Stream', component: StreamPage, params: {stream: 'personal'} },
|
||||
{ title: 'Global Stream', component: StreamPage, params: {stream: 'global'} },
|
||||
{ title: 'Timeline', component: StreamPage, params: {stream: 'personal'} },
|
||||
{ title: 'Global', component: StreamPage, params: {stream: 'global'} },
|
||||
{ title: 'Mentions', component: StreamPage, params: {stream: 'mentions'} },
|
||||
{ title: 'Bookmarks', component: StreamPage, params: {stream: 'bookmarks'} },
|
||||
{ title: 'Logout', component: {}, params: {}},
|
||||
];
|
||||
|
||||
}
|
||||
|
@ -61,7 +64,12 @@ 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, page.params);
|
||||
if (page.title === 'Logout') {
|
||||
this.storage.remove('token');
|
||||
this.nav.setRoot(LoginPage);
|
||||
} else {
|
||||
this.nav.setRoot(page.component, page.params);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -79,11 +79,6 @@
|
|||
<div *ngIf="post.counts.replies > 0">{{ post.counts.replies }}</div>
|
||||
</button>
|
||||
</ion-col>
|
||||
<!-- <ion-col>
|
||||
<button ion-button icon-left clear small block>
|
||||
<ion-icon name="more"></ion-icon>
|
||||
</button>
|
||||
</ion-col> -->
|
||||
</ion-row>
|
||||
</ion-card>
|
||||
</ion-list>
|
||||
|
|
|
@ -21,6 +21,7 @@ export class StreamPage {
|
|||
since_id: string;
|
||||
before_id: string;
|
||||
fetcher: any;
|
||||
fcaller: any;
|
||||
myUsername: string;
|
||||
|
||||
constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController) {
|
||||
|
@ -32,10 +33,20 @@ export class StreamPage {
|
|||
this.fetchPosts();
|
||||
break;
|
||||
case 'personal':
|
||||
this.title = 'Home';
|
||||
this.title = 'Timeline';
|
||||
this.fetcher = pnut.personal;
|
||||
this.fetchPosts();
|
||||
break;
|
||||
case 'mentions':
|
||||
this.title = 'Mentions';
|
||||
this.fetcher = pnut.mentions;
|
||||
this.fetchMyPosts();
|
||||
break;
|
||||
case 'bookmarks':
|
||||
this.title = 'Bookmarks';
|
||||
this.fetcher = pnut.bookmarks;
|
||||
this.fetchMyPosts();
|
||||
break;
|
||||
}
|
||||
pnut.user('me').then(res => {
|
||||
this.myUsername = res.data.username;
|
||||
|
@ -45,7 +56,13 @@ export class StreamPage {
|
|||
}
|
||||
|
||||
fetchOlderPosts(infiniteScroll) {
|
||||
this.fetcher({include_raw: 1, before_id: this.before_id, count: 40}).then(res => {
|
||||
let params = {include_raw: 1, before_id: this.before_id, count: 40};
|
||||
if (this.title === 'Mentions') {
|
||||
this.fcaller = this.fetcher('me', params);
|
||||
} else {
|
||||
this.fcaller = this.fetcher(params);
|
||||
}
|
||||
this.fcaller.then(res => {
|
||||
if (res.data.length > 0) {
|
||||
this.posts.push.apply(this.posts, res.data);
|
||||
this.before_id = res.meta.min_id;
|
||||
|
@ -59,7 +76,13 @@ export class StreamPage {
|
|||
}
|
||||
|
||||
fetchNewerPosts(refresher) {
|
||||
this.fetcher({include_raw: 1, since_id: this.since_id, count: 40}).then(res => {
|
||||
let params = {include_raw: 1, since_id: this.since_id, count: 40};
|
||||
if (this.title === 'Mentions') {
|
||||
this.fcaller = this.fetcher('me', params);
|
||||
} else {
|
||||
this.fcaller = this.fetcher(params);
|
||||
}
|
||||
this.fcaller.then(res => {
|
||||
if (res.data.length > 0) {
|
||||
Array.prototype.unshift.apply(this.posts, res.data);
|
||||
this.since_id = res.meta.max_id;
|
||||
|
@ -93,6 +116,19 @@ export class StreamPage {
|
|||
});
|
||||
}
|
||||
|
||||
fetchMyPosts() {
|
||||
console.log('-- fetching mentions --');
|
||||
this.fetcher('me', {include_raw: 1, count: 40}).then(res => {
|
||||
this.posts = res.data;
|
||||
this.since_id = res.meta.max_id;
|
||||
this.before_id = res.meta.min_id;
|
||||
console.log('since_id: ' + this.since_id);
|
||||
console.log('before_id: ' + this.before_id);
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
});
|
||||
}
|
||||
|
||||
bookmark(postid, bookmarked) {
|
||||
if (bookmarked) {
|
||||
pnut.deleteBookmark(postid).then(res => {
|
||||
|
|
Reference in a new issue