fix: Account for missing localStorage (browser security settings?)

This commit is contained in:
Tom Moor
2019-09-21 12:42:28 -07:00
parent 690299ac6b
commit dd5e30f414

View File

@@ -8,7 +8,9 @@ import type { Toast } from '../types';
class UiStore { class UiStore {
@observable @observable
theme: 'light' | 'dark' = window.localStorage.getItem('theme') || 'light'; theme: 'light' | 'dark' = (window.localStorage &&
window.localStorage.getItem('theme')) ||
'light';
@observable activeModalName: ?string; @observable activeModalName: ?string;
@observable activeModalProps: ?Object; @observable activeModalProps: ?Object;
@observable activeDocumentId: ?string; @observable activeDocumentId: ?string;
@@ -21,7 +23,10 @@ class UiStore {
@action @action
toggleDarkMode = () => { toggleDarkMode = () => {
this.theme = this.theme === 'dark' ? 'light' : 'dark'; this.theme = this.theme === 'dark' ? 'light' : 'dark';
window.localStorage.setItem('theme', this.theme);
if (window.localStorage) {
window.localStorage.setItem('theme', this.theme);
}
}; };
@action @action