packages/core: fix localStorage check in AppThemeSelector

This commit is contained in:
Patrik Oldsberg
2020-05-15 14:13:24 +02:00
parent a386750b7d
commit f3abf95f7f
@@ -23,16 +23,20 @@ export class AppThemeSelector implements AppThemeApi {
static createWithStorage(themes: AppTheme[]) {
const selector = new AppThemeSelector(themes);
if (!window.localStorage) {
return selector;
}
const initialThemeId =
window?.localStorage.getItem(STORAGE_KEY) ?? undefined;
window.localStorage.getItem(STORAGE_KEY) ?? undefined;
selector.setActiveThemeId(initialThemeId);
selector.activeThemeId$().subscribe((themeId) => {
if (themeId) {
window?.localStorage.setItem(STORAGE_KEY, themeId);
window.localStorage.setItem(STORAGE_KEY, themeId);
} else {
window?.localStorage.removeItem(STORAGE_KEY);
window.localStorage.removeItem(STORAGE_KEY);
}
});