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
1 changed files with 7 additions and 2 deletions

View File

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