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
@@ -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);
}
}