app.component.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { Component, ViewChild } from "@angular/core";
  2. import { Nav, Platform } from "ionic-angular";
  3. import { StatusBar } from "@ionic-native/status-bar";
  4. import { SplashScreen } from "@ionic-native/splash-screen";
  5. import { Storage } from "@ionic/storage";
  6. import { AuthProvider } from "../providers/auth/auth";
  7. import { HomePage } from "../pages/home/home";
  8. import { SearchPage } from "../pages/search/search";
  9. import { SettingsPage } from "../pages/settings/settings";
  10. import { LoginPage } from "../pages/login/login";
  11. import { ProfilePage } from "../pages/profile/profile";
  12. import { TwitterApiProvider } from "../providers/twitter-api/twitter-api";
  13. @Component({
  14. templateUrl: "app.html"
  15. })
  16. export class MyApp {
  17. @ViewChild(Nav)
  18. nav: Nav;
  19. rootPage: any;
  20. pages: Array<{ title: string; icon: string; component: any }>;
  21. user: any;
  22. constructor(
  23. platform: Platform,
  24. statusBar: StatusBar,
  25. splashScreen: SplashScreen,
  26. private authProvider: AuthProvider,
  27. private twitter: TwitterApiProvider,
  28. private storage: Storage
  29. ) {
  30. platform
  31. .ready()
  32. .then(() => {
  33. // Okay, so the platform is ready and our plugins are available.
  34. // Here you can do any higher level native things you might need.
  35. //this.setHomepage();
  36. statusBar.styleDefault();
  37. splashScreen.hide();
  38. return this.authProvider.isLoggedIn();
  39. })
  40. .then(isLoggedIn => {
  41. this.rootPage = isLoggedIn ? HomePage : LoginPage;
  42. return this.storage.get("userId");
  43. })
  44. .then(userId => this.twitter.fetchUser(userId))
  45. .then(res => {
  46. this.user = res;
  47. });
  48. this.pages = [
  49. { title: "Home", icon: "home", component: HomePage },
  50. { title: "Search", icon: "search", component: SearchPage },
  51. { title: "Settings", icon: "settings", component: SettingsPage }
  52. ];
  53. }
  54. showProfile(userId) {
  55. this.nav.push(ProfilePage, { userId });
  56. }
  57. openPage(page) {
  58. this.nav.push(page.component);
  59. }
  60. logout() {
  61. this.authProvider.logout();
  62. this.nav.setRoot(LoginPage);
  63. }
  64. get banner() {
  65. if (this.user.profile_banner_url) {
  66. return this.user.profile_banner_url;
  67. } else {
  68. return this.user.profile_background_image_url_https;
  69. }
  70. }
  71. }