-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathapp.component.ts
More file actions
76 lines (64 loc) · 2.79 KB
/
app.component.ts
File metadata and controls
76 lines (64 loc) · 2.79 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
import { Actions, createDispatchMap, ofActionSuccessful, select } from '@ngxs/store';
import { filter, take } from 'rxjs';
import { ChangeDetectionStrategy, Component, DestroyRef, effect, inject, OnInit } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { NavigationEnd, Router, RouterOutlet } from '@angular/router';
import { ENVIRONMENT } from '@core/provider/environment.provider';
import { GetCurrentUser } from '@core/store/user';
import { GetEmails, UserEmailsSelectors } from '@core/store/user-emails';
import { ConfirmEmailComponent } from './shared/components/confirm-email/confirm-email.component';
import { FullScreenLoaderComponent } from './shared/components/full-screen-loader/full-screen-loader.component';
import { ToastComponent } from './shared/components/toast/toast.component';
import { CustomDialogService } from './shared/services/custom-dialog.service';
import { GoogleTagManagerService } from 'angular-google-tag-manager';
@Component({
selector: 'osf-root',
imports: [RouterOutlet, ToastComponent, FullScreenLoaderComponent],
templateUrl: './app.component.html',
styleUrl: './app.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent implements OnInit {
private readonly googleTagManagerService = inject(GoogleTagManagerService);
private readonly destroyRef = inject(DestroyRef);
private readonly customDialogService = inject(CustomDialogService);
private readonly router = inject(Router);
private readonly environment = inject(ENVIRONMENT);
private readonly actions$ = inject(Actions);
private readonly actions = createDispatchMap({ getCurrentUser: GetCurrentUser, getEmails: GetEmails });
unverifiedEmails = select(UserEmailsSelectors.getUnverifiedEmails);
constructor() {
effect(() => {
if (this.unverifiedEmails().length) {
this.showEmailDialog();
}
});
}
ngOnInit(): void {
this.actions.getCurrentUser();
this.actions$.pipe(ofActionSuccessful(GetCurrentUser), take(1)).subscribe(() => {
this.actions.getEmails();
});
if (this.environment.googleTagManagerId) {
this.router.events
.pipe(
filter((event) => event instanceof NavigationEnd),
takeUntilDestroyed(this.destroyRef)
)
.subscribe((event: NavigationEnd) => {
this.googleTagManagerService.pushTag({
event: 'page',
pageName: event.urlAfterRedirects,
});
});
}
}
private showEmailDialog() {
const unverifiedEmailsData = this.unverifiedEmails();
this.customDialogService.open(ConfirmEmailComponent, {
header: unverifiedEmailsData[0].isMerge ? 'home.confirmEmail.merge.title' : 'home.confirmEmail.add.title',
width: '448px',
data: unverifiedEmailsData,
});
}
}