61 lines
1.9 KiB
TypeScript
61 lines
1.9 KiB
TypeScript
import { Component, ViewChild } from '@angular/core';
|
|
import { Nav, Platform } from 'ionic-angular';
|
|
import { StatusBar } from '@ionic-native/status-bar';
|
|
import { SplashScreen } from '@ionic-native/splash-screen';
|
|
import { Storage } from '@ionic/storage';
|
|
|
|
// import { HomePage } from '../pages/home/home';
|
|
import { ListPage } from '../pages/list/list';
|
|
import { LoginPage } from '../pages/login/login';
|
|
import { StreamPage } from '../pages/stream/stream';
|
|
|
|
import * as pnut from 'pnut-butter';
|
|
|
|
@Component({
|
|
templateUrl: 'app.html'
|
|
})
|
|
export class MyApp {
|
|
@ViewChild(Nav) nav: Nav;
|
|
|
|
rootPage: any = LoginPage;
|
|
|
|
pages: Array<{title: string, component: any, params: Object}>;
|
|
|
|
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, private storage: Storage) {
|
|
this.initializeApp();
|
|
|
|
// used for an example of ngFor and navigation
|
|
this.pages = [
|
|
{ title: 'Global Stream', component: StreamPage, params: {stream: 'global'} },
|
|
{ title: 'Personal Stream', component: StreamPage, params: {stream: 'personal'} },
|
|
{ title: 'List', component: ListPage , params: {}},
|
|
];
|
|
|
|
}
|
|
|
|
initializeApp() {
|
|
console.log('--- initializeApp ---');
|
|
this.storage.get('token').then((val) => {
|
|
if (val.length > 1) {
|
|
pnut.token = val;
|
|
this.nav.setRoot(StreamPage, {stream: 'global'});
|
|
}
|
|
}).catch(err => {
|
|
console.log('ERROR: ' + err);
|
|
});
|
|
|
|
this.platform.ready().then(() => {
|
|
// Okay, so the platform is ready and our plugins are available.
|
|
// Here you can do any higher level native things you might need.
|
|
this.statusBar.styleDefault();
|
|
this.splashScreen.hide();
|
|
});
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
}
|