-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.ts
More file actions
216 lines (200 loc) · 6.9 KB
/
app.ts
File metadata and controls
216 lines (200 loc) · 6.9 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import { RouteMeta } from '@analogjs/router';
import { Component, inject, OnInit } from '@angular/core';
import { NavigationEnd, Router, RouterOutlet } from '@angular/router';
import { LucideAngularModule } from 'lucide-angular';
import { concatMap, first, firstValueFrom, mergeMap, tap } from 'rxjs';
import { AppInitializerService } from './app.initializer';
import { ColorSchemeSwitcherComponent } from './components/theme/color-scheme-switcher.component';
import {
IfLoggedDirective,
IfNotLoggedDirective,
} from './directives/if-logged.directive';
import {
IfNavHiddenDirective,
IfNavShownDirective,
} from './directives/if-nav.directive';
import { ShowNavGuard } from './guards/nav.guard';
import { AuthService } from './services/auth.service';
import { ErrorHandlerService } from './services/error-handler.service';
import { ProfileService } from './services/profile.service';
import { ReleaseService } from './services/release.service';
export const routeMeta: RouteMeta = {
canActivate: [ShowNavGuard],
};
@Component({
selector: 'app-root',
imports: [
RouterOutlet,
ColorSchemeSwitcherComponent,
IfNotLoggedDirective,
IfLoggedDirective,
IfNavShownDirective,
IfNavHiddenDirective,
LucideAngularModule,
],
template: `
<!--header class="container pico">
<nav>
<ul>
<li>
<h1><a href="/">My Dashboard</a></h1>
</li>
</ul>
<ul>
<li><a href="/dashboards">Dashboards</a></li>
<li><a href="/login" *ifNotLogged>Login</a></li>
<li><a href="#signOut" (click)="signOut()" *ifLogged>Logout</a></li>
<li><color-scheme-switcher /></li>
</ul>
</nav>
</header-->
<div
*ifNavShown
id="dashboard-list"
data-view="dashboard-list"
class="min-h-screen flex"
>
<div
class="w-16 lg:w-64 bg-white long-shadow p-4 flex flex-col items-center lg:items-start border-r border-gray-100 transition-all duration-300"
>
<a href="/" class="text-2xl font-bold text-pastel-blue mb-10 mt-2">
<img
class="w-8 h-8 lg:mr-2 inline-block align-middle"
src="/my-dashboard-logo.png"
/>
<span class="mobile-hidden lg:inline align-middle">My Dashboard</span>
</a>
<nav class="flex flex-col space-y-4 w-full">
<a
href="/dashboards"
class="flex items-center p-3 rounded-xl bg-pastel-blue/10 text-pastel-blue font-semibold transition-all duration-300 hover:bg-pastel-blue/20"
>
<i-lucide name="grid-3x3" class="w-6 h-6 mr-0 lg:mr-3"></i-lucide>
<span class="mobile-hidden lg:inline">Dashboards</span>
</a>
<a
href="/analytics"
class="flex items-center p-3 rounded-xl text-gray-600 font-medium transition-all duration-300 hover:bg-gray-100 hover:text-gray-800"
>
<i-lucide
name="chart-bar-big"
class="w-6 h-6 mr-0 lg:mr-3"
></i-lucide>
<span class="mobile-hidden lg:inline">Analytics</span>
</a>
<a
href="/settings"
class="flex items-center p-3 rounded-xl text-gray-600 font-medium transition-all duration-300 hover:bg-gray-100 hover:text-gray-800"
>
<i-lucide name="settings" class="w-6 h-6 mr-0 lg:mr-3"></i-lucide>
<span class="mobile-hidden lg:inline">Settings</span>
</a>
<button
(click)="downloadMobileApk()"
class="flex items-center p-3 rounded-xl text-gray-600 font-medium transition-all duration-300 hover:bg-gray-100 hover:text-gray-800 w-full text-left"
>
<i-lucide name="smartphone" class="w-6 h-6 mr-0 lg:mr-3"></i-lucide>
<span class="mobile-hidden lg:inline">Mobile App</span>
</button>
</nav>
<div
class="mt-auto pt-6 w-full flex flex-col items-center lg:items-start"
>
<div class="flex justify-between items-center w-full px-2">
<button
(click)="signOut()"
class="p-2 rounded-lg bg-gray-200 hover:bg-gray-300 text-red-500 font-medium transition-colors flex items-center"
>
<i-lucide name="log-out" class="w-5 h-5 mr-0 lg:mr-2"></i-lucide>
<span class="mobile-hidden lg:inline">Sign Out</span>
</button>
<color-scheme-switcher class="flex items-center" />
</div>
</div>
</div>
<div class="flex-1 p-6 lg:p-10 overflow-y-auto">
<router-outlet></router-outlet>
</div>
</div>
<ng-container *ifNavHidden>
<router-outlet></router-outlet>
</ng-container>
`,
})
export class AppComponent implements OnInit {
private readonly profileService = inject(ProfileService);
private readonly authService = inject(AuthService);
private readonly router = inject(Router);
private readonly appInitializerService = inject(AppInitializerService);
private readonly errorHandler = inject(ErrorHandlerService);
private readonly releaseService = inject(ReleaseService);
ngOnInit(): void {
this.router.events
.pipe(
concatMap(async event => {
if (
typeof location !== 'undefined' &&
location.hash.startsWith('#access_token=')
) {
const token = location.hash
.split('#access_token=')?.[1]
?.split('&')?.[0];
await firstValueFrom(this.authService.supabaseVerifyToken(token));
location.hash = '';
}
if (event instanceof NavigationEnd) {
return await this.appInitializerService.init();
}
}),
mergeMap(() => this.profileService.isLoggedIn()),
concatMap(async isLoggedIn => {
if (
!isLoggedIn &&
this.router.routerState.snapshot.url !== '/login'
) {
await this.router.navigate(['/login']);
}
})
)
.subscribe();
}
signOut() {
this.authService
.signOut()
.pipe(
first(),
tap(() => this.router.navigate(['/']))
)
.subscribe();
}
showError() {
this.errorHandler.handleError(
new Error('This feature is not available yet')
);
}
downloadMobileApk() {
this.releaseService.getMobileApkDownloadUrl().subscribe({
next: (downloadUrl) => {
if (downloadUrl) {
// Open the download URL in a new tab
window.open(downloadUrl, '_blank');
} else {
this.errorHandler
.handleError(
new Error('Mobile APK download URL not found'),
'Download Unavailable'
)
.then();
}
},
error: (error) => {
this.errorHandler
.handleError(
error,
'Download Error'
)
.then();
}
});
}
}