mirror of
https://github.com/akveo/ngx-admin.git
synced 2026-01-19 15:56:10 +01:00
fix(theme): save theme in local storage after theme changing
This commit is contained in:
parent
9e86f88fa2
commit
a878bd2d80
3 changed files with 24 additions and 16 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import {Injectable, OnDestroy} from '@angular/core';
|
||||
import {Observable} from 'rxjs';
|
||||
import {takeWhile} from 'rxjs/operators';
|
||||
import {environment} from '../../../environments/environment';
|
||||
|
||||
@Injectable()
|
||||
export class CurrentThemeService implements OnDestroy {
|
||||
|
|
@ -10,6 +11,22 @@ export class CurrentThemeService implements OnDestroy {
|
|||
subscriber.next(localStorage.theme);
|
||||
}).pipe(takeWhile(() => this.alive));
|
||||
|
||||
setCurrentTheme(themeName: string): void {
|
||||
const currentTheme = {
|
||||
themeName: themeName,
|
||||
expires_in: this.calculateExpiration(environment.currentThemeLife),
|
||||
};
|
||||
|
||||
localStorage.setItem('theme', JSON.stringify(currentTheme));
|
||||
}
|
||||
|
||||
calculateExpiration(iat: number): number {
|
||||
const currentDate = new Date().getTime();
|
||||
const timestamp = iat || Math.floor(Date.now() / 1000);
|
||||
|
||||
return Math.floor(timestamp + currentDate);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
this.alive = false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue