From b11ea8e21584c49ccdf7f9a5df51bc983be741a6 Mon Sep 17 00:00:00 2001 From: Morgan McMillian Date: Fri, 4 Aug 2017 13:22:13 -0700 Subject: [PATCH] added setting for unified timeline, issue #29 and #31 --- src/app/app.component.ts | 9 +++--- src/pages/stream/stream.ts | 59 +++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 84d4711..52cbb32 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -57,9 +57,9 @@ export class MyApp { this.statusBar.styleDefault(); this.splashScreen.hide(); - console.log('---'); - console.log(this.device.platform); - console.log('---'); + // console.log('---'); + // console.log(this.device.platform); + // console.log('---'); }); } @@ -67,7 +67,8 @@ export class MyApp { // Reset the content nav to have just this page // we wouldn't want the back button to show in this scenario if (page.title === 'Logout') { - this.storage.remove('token'); + // this.storage.remove('token'); + this.storage.clear(); this.nav.setRoot(LoginPage); } else if (page.title === 'Settings') { this.nav.push(page.component, page.params); diff --git a/src/pages/stream/stream.ts b/src/pages/stream/stream.ts index 7d6be7a..1668a91 100644 --- a/src/pages/stream/stream.ts +++ b/src/pages/stream/stream.ts @@ -1,6 +1,7 @@ import { Component, ViewChild, ChangeDetectorRef } from '@angular/core'; import { ViewController, NavController, NavParams, ModalController, Content, ToastController, PopoverController } from 'ionic-angular'; import { ThreadPage } from '../thread/thread'; +import { Storage } from '@ionic/storage'; import * as pnut from 'pnut-butter'; @@ -26,33 +27,45 @@ export class StreamPage { fcaller: any; myUsername: string; showScrollBtn: boolean = false; + showUnified: boolean; constructor(public navCtrl: NavController, public navParams: NavParams, public modalCtrl: ModalController, - private changeDetectorRef: ChangeDetectorRef, public toastCtrl: ToastController, public popoverCtrl: PopoverController) { + private changeDetectorRef: ChangeDetectorRef, public toastCtrl: ToastController, private storage: Storage, + public popoverCtrl: PopoverController) { // console.log(JSON.stringify(navParams)); - switch (navParams.data.stream) { - case 'global': - this.title = 'Global'; - this.fetcher = pnut.global; - this.fetchPosts(); - break; - case 'personal': - 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; - } + this.storage.get('unified').then((val) => { + this.showUnified = val; + + switch (navParams.data.stream) { + case 'global': + this.title = 'Global'; + this.fetcher = pnut.global; + this.fetchPosts(); + break; + case 'personal': + this.title = 'Timeline'; + console.log(this.showUnified); + this.fetcher = this.showUnified ? pnut.unified : 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; + } + + }).catch(err => { + console.log('ERROR: ' + err); + }); + + pnut.user('me').then(res => { this.myUsername = res.data.username; }).catch(err => {