123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- 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 { AuthProvider } from "../providers/auth/auth";
- import { HomePage } from "../pages/home/home";
- import { SearchPage } from "../pages/search/search";
- import { SettingsPage } from "../pages/settings/settings";
- import { LoginPage } from "../pages/login/login";
- import { ProfilePage } from "../pages/profile/profile";
- import { TwitterApiProvider } from "../providers/twitter-api/twitter-api";
- @Component({
- templateUrl: "app.html"
- })
- export class MyApp {
- @ViewChild(Nav)
- nav: Nav;
- rootPage: any;
- pages: Array<{ title: string; icon: string; component: any }>;
- user: any;
- constructor(
- platform: Platform,
- statusBar: StatusBar,
- splashScreen: SplashScreen,
- private authProvider: AuthProvider,
- private twitter: TwitterApiProvider,
- private storage: Storage
- ) {
- 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.setHomepage();
- statusBar.styleDefault();
- splashScreen.hide();
- return this.authProvider.isLoggedIn();
- })
- .then(isLoggedIn => {
- this.rootPage = isLoggedIn ? HomePage : LoginPage;
- return this.storage.get("userId");
- })
- .then(userId => this.twitter.fetchUser(userId))
- .then(res => {
- this.user = res;
- });
- this.pages = [
- { title: "Home", icon: "home", component: HomePage },
- { title: "Search", icon: "search", component: SearchPage },
- { title: "Settings", icon: "settings", component: SettingsPage }
- ];
- }
- showProfile(userId) {
- this.nav.push(ProfilePage, { userId });
- }
- openPage(page) {
- this.nav.setRoot(page.component);
- }
- logout() {
- this.authProvider.logout();
- this.nav.setRoot(LoginPage);
- }
- }
|