-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathapp.component.ts
130 lines (112 loc) · 2.91 KB
/
app.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { Router } from '@angular/router';
import { SwUpdate } from '@angular/service-worker';
import { MenuController, Platform, ToastController } from '@ionic/angular';
import { StatusBar } from '@capacitor/status-bar';
import { SplashScreen } from '@capacitor/splash-screen';
import { Storage } from '@ionic/storage-angular';
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: MenuController,
private platform: Platform,
private router: Router,
private storage: Storage,
private userData: UserData,
private swUpdate: SwUpdate,
private toastCtrl: ToastController,
) {
this.initializeApp();
}
async ngOnInit() {
await this.storage.create();
this.checkLoginStatus();
this.listenForLoginEvents();
this.swUpdate.versionUpdates.subscribe(async res => {
const toast = await this.toastCtrl.create({
message: 'Update available!',
position: 'bottom',
buttons: [
{
role: 'cancel',
text: 'Reload'
}
]
});
await toast.present();
toast
.onDidDismiss()
.then(() => this.swUpdate.activateUpdate())
.then(() => window.location.reload());
});
}
initializeApp() {
this.platform.ready().then(() => {
if (this.platform.is('hybrid')) {
StatusBar.hide();
SplashScreen.hide();
}
});
}
checkLoginStatus() {
return this.userData.isLoggedIn().then(loggedIn => {
return this.updateLoggedInStatus(loggedIn);
});
}
updateLoggedInStatus(loggedIn: boolean) {
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');
}
}