|
@@ -1,5 +1,5 @@
|
|
|
import { Component, ViewChild } from "@angular/core";
|
|
|
-import { Nav, Platform } from "ionic-angular";
|
|
|
+import { Nav, Platform, Events } from "ionic-angular";
|
|
|
import { StatusBar } from "@ionic-native/status-bar";
|
|
|
import { SplashScreen } from "@ionic-native/splash-screen";
|
|
|
import { Storage } from "@ionic/storage";
|
|
@@ -30,7 +30,8 @@ export class MyApp {
|
|
|
splashScreen: SplashScreen,
|
|
|
private authProvider: AuthProvider,
|
|
|
private twitter: TwitterApiProvider,
|
|
|
- private storage: Storage
|
|
|
+ private storage: Storage,
|
|
|
+ private events: Events
|
|
|
) {
|
|
|
platform.ready().then(() => {
|
|
|
// Okay, so the platform is ready and our plugins are available.
|
|
@@ -39,6 +40,8 @@ export class MyApp {
|
|
|
statusBar.styleDefault();
|
|
|
splashScreen.hide();
|
|
|
this.initApp();
|
|
|
+
|
|
|
+ this.events.subscribe("user:login", () => this.setUser());
|
|
|
});
|
|
|
|
|
|
this.pages = [
|
|
@@ -53,13 +56,17 @@ export class MyApp {
|
|
|
|
|
|
if (isLoggedIn) {
|
|
|
this.rootPage = HomePage;
|
|
|
- const userId = await this.storage.get("userId");
|
|
|
- this.user = await this.twitter.fetchUser(userId);
|
|
|
+ await this.setUser();
|
|
|
} else {
|
|
|
this.rootPage = LoginPage;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async setUser() {
|
|
|
+ const userId = await this.storage.get("userId");
|
|
|
+ this.user = await this.twitter.fetchUser(userId);
|
|
|
+ }
|
|
|
+
|
|
|
showProfile(userId) {
|
|
|
this.nav.push(ProfilePage, { userId });
|
|
|
}
|