-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.component.ts
114 lines (106 loc) · 3.4 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
import {
AfterViewInit,
ChangeDetectorRef,
Component,
OnDestroy,
OnInit,
} from '@angular/core';
import { Deeplinks } from '@awesome-cordova-plugins/deeplinks/ngx';
import { MenuController, NavController, Platform } from '@ionic/angular';
import { map, Observable } from 'rxjs';
import { Subscription } from 'rxjs/internal/Subscription';
import { UserService } from './user.service';
@Component({
selector: 'app-root',
template: `
<ion-app>
<ion-split-pane contentId="main">
<ion-menu side="start" contentId="main">
<ion-header>
<ion-toolbar translucent color="primary">
<ion-title>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-menu-toggle autoHide="false">
<ion-list>
<ion-item
routerDirection="root"
routerLink="/account"
lines="none"
detail="false"
*ngIf="isAuthenticated | async"
>
<ion-icon slot="start" name="person-circle"></ion-icon>
<ion-label>{{ user.current.displayName }}</ion-label>
</ion-item>
<ion-item
lines="none"
detail="false"
*ngIf="!(isAuthenticated | async)"
(click)="user.login()"
>
<ion-icon slot="start" name="person-circle"></ion-icon>
<ion-label>Login</ion-label>
</ion-item>
<ion-item
routerDirection="root"
routerLink="/home"
lines="none"
detail="false"
>
<ion-icon slot="start" name="home"></ion-icon>
<ion-label>Home</ion-label>
</ion-item>
</ion-list>
</ion-menu-toggle>
</ion-content>
</ion-menu>
<ion-router-outlet id="main"></ion-router-outlet>
</ion-split-pane>
</ion-app>
`,
styles: [],
})
export class AppComponent implements OnInit, AfterViewInit, OnDestroy {
private deeplinksRouteSubscription?: Subscription;
constructor(
private menuController: MenuController,
readonly user: UserService,
private platform: Platform,
private deeplinks: Deeplinks,
private navController: NavController,
private cdr: ChangeDetectorRef
) {}
ngOnInit(): void {
console.log('PLATFORMS: ' + this.platform.platforms());
if (this.platform.is('capacitor')) {
this.setupDeeplinks();
}
}
public openMenu() {
return this.menuController.open();
}
ngAfterViewInit(): void {}
ngOnDestroy() {
this.deeplinksRouteSubscription?.unsubscribe();
}
get isAuthenticated(): Observable<boolean> {
return this.user.valueChanges.pipe(map(u => u.isAuthenticated))
}
private setupDeeplinks() {
this.deeplinksRouteSubscription = this.deeplinks
.routeWithNavController(this.navController, {})
.subscribe({
next: async (match) => {
console.log('Deeplink matched: ', match);
await this.navController.navigateForward(
match.$link.path + '?' + match.$link.queryString
);
this.cdr.detectChanges();
},
error: (nomatch) =>
console.error("Deeplink didn't match", JSON.stringify(nomatch)),
});
}
}