11import { Actions , createDispatchMap , ofActionSuccessful , select } from '@ngxs/store' ;
22
3- import { filter , take } from 'rxjs' ;
3+ import { take , timer } from 'rxjs' ;
44
55import { ChangeDetectionStrategy , Component , DestroyRef , effect , inject , OnInit } from '@angular/core' ;
66import { takeUntilDestroyed } from '@angular/core/rxjs-interop' ;
7- import { NavigationEnd , Router , RouterOutlet } from '@angular/router' ;
7+ import {
8+ NavigationCancel ,
9+ NavigationEnd ,
10+ NavigationError ,
11+ NavigationStart ,
12+ Router ,
13+ RouterOutlet ,
14+ } from '@angular/router' ;
815
916import { ENVIRONMENT } from '@core/provider/environment.provider' ;
1017import { GetCurrentUser } from '@core/store/user' ;
@@ -14,6 +21,7 @@ import { ConfirmEmailComponent } from './shared/components/confirm-email/confirm
1421import { FullScreenLoaderComponent } from './shared/components/full-screen-loader/full-screen-loader.component' ;
1522import { ToastComponent } from './shared/components/toast/toast.component' ;
1623import { CustomDialogService } from './shared/services/custom-dialog.service' ;
24+ import { LoaderService } from './shared/services/loader.service' ;
1725
1826import { GoogleTagManagerService } from 'angular-google-tag-manager' ;
1927
@@ -32,6 +40,7 @@ export class AppComponent implements OnInit {
3240 private readonly environment = inject ( ENVIRONMENT ) ;
3341 private readonly actions$ = inject ( Actions ) ;
3442 private readonly actions = createDispatchMap ( { getCurrentUser : GetCurrentUser , getEmails : GetEmails } ) ;
43+ private readonly loaderService = inject ( LoaderService ) ;
3544
3645 unverifiedEmails = select ( UserEmailsSelectors . getUnverifiedEmails ) ;
3746
@@ -50,19 +59,26 @@ export class AppComponent implements OnInit {
5059 this . actions . getEmails ( ) ;
5160 } ) ;
5261
53- if ( this . environment . googleTagManagerId ) {
54- this . router . events
55- . pipe (
56- filter ( ( event ) => event instanceof NavigationEnd ) ,
57- takeUntilDestroyed ( this . destroyRef )
58- )
59- . subscribe ( ( event : NavigationEnd ) => {
60- this . googleTagManagerService . pushTag ( {
61- event : 'page' ,
62- pageName : event . urlAfterRedirects ,
63- } ) ;
62+ this . router . events . pipe ( takeUntilDestroyed ( this . destroyRef ) ) . subscribe ( ( event ) => {
63+ if ( event instanceof NavigationStart ) {
64+ this . loaderService . show ( ) ;
65+ } else if (
66+ event instanceof NavigationEnd ||
67+ event instanceof NavigationCancel ||
68+ event instanceof NavigationError
69+ ) {
70+ timer ( 500 )
71+ . pipe ( takeUntilDestroyed ( this . destroyRef ) )
72+ . subscribe ( ( ) => this . loaderService . hide ( ) ) ;
73+ }
74+
75+ if ( this . environment . googleTagManagerId && event instanceof NavigationEnd ) {
76+ this . googleTagManagerService . pushTag ( {
77+ event : 'page' ,
78+ pageName : event . urlAfterRedirects ,
6479 } ) ;
65- }
80+ }
81+ } ) ;
6682 }
6783
6884 private showEmailDialog ( ) {
0 commit comments