fetching the global stream

This commit is contained in:
Morgan McMillian 2017-06-10 06:55:32 -07:00
parent d395504629
commit 9dbde32fbe
8 changed files with 108 additions and 12 deletions

View file

@ -24,9 +24,10 @@ limitations under the License.
* Install Node.js (https://nodejs.org) * Install Node.js (https://nodejs.org)
* Install the latest Ionic and Cordova tools * Install the latest Ionic and Cordova tools
```bash
npm install -g ionic cordova ```bash
``` npm install -g ionic cordova
```
## Platform build dependencies ## Platform build dependencies

View file

@ -4,9 +4,11 @@ import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen'; import { SplashScreen } from '@ionic-native/splash-screen';
import { Storage } from '@ionic/storage'; import { Storage } from '@ionic/storage';
import { HomePage } from '../pages/home/home'; // import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list'; import { ListPage } from '../pages/list/list';
import { LoginPage } from '../pages/login/login'; import { LoginPage } from '../pages/login/login';
import { StreamPage } from '../pages/stream/stream';
import * as pnut from 'pnut-butter'; import * as pnut from 'pnut-butter';
@Component({ @Component({
@ -24,7 +26,7 @@ export class MyApp {
// used for an example of ngFor and navigation // used for an example of ngFor and navigation
this.pages = [ this.pages = [
{ title: 'Home', component: HomePage }, { title: 'Global Stream', component: StreamPage },
{ title: 'List', component: ListPage }, { title: 'List', component: ListPage },
]; ];
@ -35,7 +37,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(HomePage); this.nav.setRoot(StreamPage);
} }
}).catch(err => { }).catch(err => {
console.log('ERROR: ' + err); console.log('ERROR: ' + err);

View file

@ -6,6 +6,7 @@ import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home'; import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list'; import { ListPage } from '../pages/list/list';
import { LoginPage } from '../pages/login/login'; import { LoginPage } from '../pages/login/login';
import { StreamPage } from '../pages/stream/stream';
import { StatusBar } from '@ionic-native/status-bar'; import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen'; import { SplashScreen } from '@ionic-native/splash-screen';
@ -16,7 +17,8 @@ import { IonicStorageModule } from '@ionic/storage';
MyApp, MyApp,
HomePage, HomePage,
ListPage, ListPage,
LoginPage LoginPage,
StreamPage
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
@ -28,7 +30,8 @@ import { IonicStorageModule } from '@ionic/storage';
MyApp, MyApp,
HomePage, HomePage,
ListPage, ListPage,
LoginPage LoginPage,
StreamPage
], ],
providers: [ providers: [
StatusBar, StatusBar,

View file

@ -4,7 +4,7 @@ import { Storage } from '@ionic/storage';
import { HomePage } from '../home/home'; import { HomePage } from '../home/home';
import { OauthCordova } from 'ng2-cordova-oauth/platform/cordova'; import { OauthCordova } from 'ng2-cordova-oauth/platform/cordova';
import { OauthBrowser } from 'ng2-cordova-oauth/platform/browser'; // import { OauthBrowser } from 'ng2-cordova-oauth/platform/browser';
import { PnutAuth } from '../../providers/pnut-oauth'; import { PnutAuth } from '../../providers/pnut-oauth';
import * as pnut from 'pnut-butter'; import * as pnut from 'pnut-butter';
@ -22,7 +22,7 @@ import * as pnut from 'pnut-butter';
export class LoginPage { export class LoginPage {
private oauth: OauthCordova = new OauthCordova(); private oauth: OauthCordova = new OauthCordova();
private oauthb: OauthBrowser = new OauthBrowser(); // private oauthb: OauthBrowser = new OauthBrowser();
private pnutProvider: PnutAuth = new PnutAuth({ private pnutProvider: PnutAuth = new PnutAuth({
appScope: ['basic','stream','write_post'] appScope: ['basic','stream','write_post']
}); });
@ -32,8 +32,8 @@ export class LoginPage {
} }
login() { login() {
this.oauthb.logInVia(this.pnutProvider).then(success => { this.oauth.logInVia(this.pnutProvider).then(success => {
// console.log('RESULT: ' + JSON.stringify(success)); console.log('RESULT: ' + JSON.stringify(success));
this.storage.set('token', success['access_token']); this.storage.set('token', success['access_token']);
pnut.token = success['access_token']; pnut.token = success['access_token'];
this.navCtrl.setRoot(HomePage); this.navCtrl.setRoot(HomePage);

View file

@ -0,0 +1,28 @@
<!--
Generated template for the StreamPage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar>
<ion-title>stream</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-list>
<ion-item *ngFor="let post of posts" (click)="goParkDetails(park)" text-wrap>
<ion-avatar item-start>
<img src="{{post.user.content.avatar_image.link}}">
</ion-avatar>
<h2>{{post.user.username}}</h2>
<p>{{post.content.text}}</p>
</ion-item>
</ion-list>
</ion-content>

View file

@ -0,0 +1,16 @@
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { StreamPage } from './stream';
@NgModule({
declarations: [
StreamPage,
],
imports: [
IonicPageModule.forChild(StreamPage),
],
exports: [
StreamPage
]
})
export class StreamPageModule {}

View file

@ -0,0 +1,11 @@
page-stream {
.item-md ion-avatar img {
border-radius: 0;
}
.item-wp ion-avatar img {
border-radius: 0;
}
.item-ios ion-avatar img {
border-radius: 0;
}
}

View file

@ -0,0 +1,35 @@
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import * as pnut from 'pnut-butter';
/**
* Generated class for the StreamPage page.
*
* See http://ionicframework.com/docs/components/#navigation for more info
* on Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-stream',
templateUrl: 'stream.html',
})
export class StreamPage {
posts: Array<Object> = []
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.fetchGlobal();
}
fetchGlobal() {
console.log('-- fetching global stream --');
pnut.global().then(res => {
// console.log(res);
this.posts = res.data;
}).catch(err => {
console.log(err);
});
}
}