build(theme): remove unnecessary dependency on @ngx-pwa/local-storage (#126)

Remove unnecessary dependency and use browser local storage to store
theme instead.

Fixes #125
This commit is contained in:
Abhay Chawla
2018-07-14 21:47:29 +05:30
committed by GitHub
parent a57846b88b
commit 80e82677de
4 changed files with 9 additions and 17 deletions
-5
View File
@@ -685,11 +685,6 @@
"webpack-sources": "1.1.0"
}
},
"@ngx-pwa/local-storage": {
"version": "6.0.0-rc.0",
"resolved": "https://registry.npmjs.org/@ngx-pwa/local-storage/-/local-storage-6.0.0-rc.0.tgz",
"integrity": "sha512-ks+5nSjSbErv8u22jsu4zKUDcQuXTum9k5qVptq2+mytzxXfNZLMNz3NT91Ww72axgsoDKBNEYNaLuY4ST5pLg=="
},
"@ngx-rocket/ascii-logo": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@ngx-rocket/ascii-logo/-/ascii-logo-1.1.0.tgz",
-1
View File
@@ -37,7 +37,6 @@
"@angular/platform-browser-dynamic": "^6.0.6",
"@angular/router": "^6.0.6",
"@angular/service-worker": "^6.0.6",
"@ngx-pwa/local-storage": "^6.0.0-rc.0",
"@ngx-translate/core": "^10.0.2",
"@swimlane/ngx-charts": "^8.1.0",
"angular-archwizard": "^3.0.0",
@@ -55,9 +55,10 @@ export class ThemePickerComponent implements OnInit {
constructor(public themeManagerService: ThemeManagerService,
private themeStorageService: ThemeStorageService) {
this.themeStorageService.getTheme().subscribe((theme) => {
const theme = this.themeStorageService.getTheme();
if (theme) {
this.installTheme(theme);
});
}
}
ngOnInit() { }
@@ -1,8 +1,5 @@
import {Injectable, EventEmitter} from '@angular/core';
import { LocalStorage } from '@ngx-pwa/local-storage';
import { Observable } from 'rxjs';
import { Theme } from './theme.model';
@Injectable({
@@ -13,21 +10,21 @@ export class ThemeStorageService {
private themeStorageKey = 'mifosXTheme';
onThemeUpdate: EventEmitter<Theme>;
constructor(private localStorage: LocalStorage) {
constructor() {
this.onThemeUpdate = new EventEmitter<Theme>();
}
storeTheme(mifosXTheme: Theme) {
this.localStorage.setItem(this.themeStorageKey, mifosXTheme)
.subscribe(() => this.onThemeUpdate.emit(mifosXTheme));
localStorage.setItem(this.themeStorageKey, JSON.stringify(mifosXTheme));
this.onThemeUpdate.emit(mifosXTheme);
}
getTheme(): Observable<Theme> {
return this.localStorage.getItem<Theme>(this.themeStorageKey);
getTheme(): Theme {
return JSON.parse(localStorage.getItem(this.themeStorageKey));
}
clearTheme() {
this.localStorage.removeItemSubscribe(this.themeStorageKey);
localStorage.removeItem(this.themeStorageKey);
}
}