diff --git a/src/app/@core/guard/theme.guard.ts b/src/app/@core/guard/theme.guard.ts index c02432d9..9c3f6671 100644 --- a/src/app/@core/guard/theme.guard.ts +++ b/src/app/@core/guard/theme.guard.ts @@ -15,12 +15,16 @@ export class ThemeGuard implements CanActivate { ): Observable | Promise | boolean { return this.currentThemeService.currentTheme$.pipe( map(theme => { - const currentThemeExpiration = JSON.parse(theme).expires_in; - const currentDate = new Date().getTime(); - if (!theme || currentDate > currentThemeExpiration) { + if (!theme || this.hasExpired(theme)) { this.router.navigate(['themes']); } return true; })); } + + private hasExpired(theme): boolean { + const currentThemeExpiration = JSON.parse(theme).expires_in; + const currentDate = new Date().getTime(); + return currentDate > currentThemeExpiration; + } } diff --git a/src/app/@core/utils/theme.service.ts b/src/app/@core/utils/theme.service.ts index 8b663ecc..0ca26925 100644 --- a/src/app/@core/utils/theme.service.ts +++ b/src/app/@core/utils/theme.service.ts @@ -21,7 +21,7 @@ export class CurrentThemeService implements OnDestroy { } getCurrentTheme(): string { - return JSON.parse(localStorage.theme).themeName; + return localStorage.theme ? JSON.parse(localStorage.theme).themeName : 'default'; } calculateExpiration(iat: number): number { diff --git a/src/app/@theme/components/header/header.component.ts b/src/app/@theme/components/header/header.component.ts index 10a45648..70c2ba23 100644 --- a/src/app/@theme/components/header/header.component.ts +++ b/src/app/@theme/components/header/header.component.ts @@ -62,15 +62,14 @@ export class HeaderComponent implements OnInit, OnDestroy { private analytics: AnalyticsService, private currentThemeService: CurrentThemeService, ) { - } - - ngOnInit() { this.materialTheme$ = new Observable(subscriber => { const themeName: string = this.currentThemeService.getCurrentTheme(); subscriber.next(themeName.startsWith('material')); }); + } + ngOnInit() { this.currentTheme = this.themeService.currentTheme; this.userService.getUsers() @@ -104,6 +103,10 @@ export class HeaderComponent implements OnInit, OnDestroy { changeTheme(themeName: string) { this.currentThemeService.setCurrentTheme(themeName); this.themeService.changeTheme(themeName); + + this.materialTheme$ = new Observable(subscriber => { + subscriber.next(this.currentThemeService.getCurrentTheme().startsWith('material')); + }); } toggleSidebar(): boolean { diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 00381cbe..652aaee6 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -53,8 +53,8 @@ export const routes: Routes = [ }, ], }, - { path: '', redirectTo: 'themes', pathMatch: 'full' }, - { path: '**', redirectTo: 'themes' }, + { path: '', redirectTo: 'pages/dashboard', pathMatch: 'full' }, + { path: '**', redirectTo: 'pages/dashboard' }, ]; const config: ExtraOptions = { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index fac5d875..09e9d61b 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -11,6 +11,7 @@ import { NbThemeService } from '@nebular/theme'; import { AnalyticsService } from './@core/utils/analytics.service'; import { AbService } from './@core/utils/ab.service'; import { SeoService } from './@core/utils/seo.service'; +import { CurrentThemeService } from './@core/utils/theme.service'; @Component({ selector: 'ngx-app', @@ -24,7 +25,8 @@ export class AppComponent implements OnInit { private seoService: SeoService, private activatedRoute: ActivatedRoute, private abService: AbService, - private themeService: NbThemeService) { + private themeService: NbThemeService, + private currentThemeService: CurrentThemeService) { this.themeService.onThemeChange() .subscribe((theme: any) => { @@ -35,6 +37,8 @@ export class AppComponent implements OnInit { .subscribe((params: any) => { if (params.theme && this.themes.includes(params.theme)) { this.themeService.changeTheme(params.theme); + } else { + this.themeService.changeTheme(this.currentThemeService.getCurrentTheme()); } }); }