import { Component , OnInit , ViewEncapsulation } from '@angular/core' ; import { Router } from '@angular/router' ; import { MenuController } from '@ionic/angular' ; import { Storage } from '@ionic/storage' ; import { UserData } from './providers/user-data' ; @ Component ( { selector : 'app-root' , templateUrl : './app.component.html' , styleUrls : [ './app.component.scss' ] , encapsulation : ViewEncapsulation . None } ) export class AppComponent implements OnInit { appPages = [ { title : 'Schedule' , url : '/app/tabs/schedule' , icon : 'calendar' } , { title : 'Speakers' , url : '/app/tabs/speakers' , icon : 'people' } , { title : 'Map' , url : '/app/tabs/map' , icon : 'map' } , { title : 'About' , url : '/app/tabs/about' , icon : 'information-circle' } ] ; loggedIn = false ; dark = false ; constructor ( private menu , private router , private storage , private userData ) { } async ngOnInit ( ) { this . checkLoginStatus ( ) ; this . listenForLoginEvents ( ) ; } checkLoginStatus ( ) { return this . userData . isLoggedIn ( ) . then ( loggedIn => { return this . updateLoggedInStatus ( loggedIn ) ; } ) ; } updateLoggedInStatus ( loggedIn ) { setTimeout ( ( ) => { this . loggedIn = loggedIn ; } , 300 ) ; } listenForLoginEvents ( ) { window . addEventListener ( 'user:login' , ( ) => { this . updateLoggedInStatus ( true ) ; } ) ; window . addEventListener ( 'user:signup' , ( ) => { this . updateLoggedInStatus ( true ) ; } ) ; window . addEventListener ( 'user:logout' , ( ) => { this . updateLoggedInStatus ( false ) ; } ) ; } logout ( ) { this . userData . logout ( ) . then ( ( ) => { return this . router . navigateByUrl ( '/app/tabs/schedule' ) ; } ) ; } openTutorial ( ) { this . menu . enable ( false ) ; this . storage . set ( 'ion_did_tutorial' , false ) ; this . router . navigateByUrl ( '/tutorial' ) ; } }