From cd65ed97cdb053d8ccb9b48c1891affc8718493b Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Mon, 19 Jun 2017 22:05:39 -0700 Subject: [PATCH] include mentions, bookmarks, and logout button --- src/app/app.component.ts | 14 +++++++++--- src/pages/stream/stream.html | 5 ----- src/pages/stream/stream.ts | 42 +++++++++++++++++++++++++++++++++--- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index a32904e..9b6e578 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -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); + } } } diff --git a/src/pages/stream/stream.html b/src/pages/stream/stream.html index 1ff8778..fb49a90 100644 --- a/src/pages/stream/stream.html +++ b/src/pages/stream/stream.html @@ -79,11 +79,6 @@
{{ post.counts.replies }}
- diff --git a/src/pages/stream/stream.ts b/src/pages/stream/stream.ts index 97ec45f..6f4973c 100644 --- a/src/pages/stream/stream.ts +++ b/src/pages/stream/stream.ts @@ -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 => {