diff --git a/ui/src/index.tsx b/ui/src/index.tsx index d4df6be..4d4e96c 100644 --- a/ui/src/index.tsx +++ b/ui/src/index.tsx @@ -6,9 +6,17 @@ import App from "./App"; import store from "./store"; import * as serviceWorker from "./serviceWorker"; import { saveState } from "./localStorage"; +import { SettingsState } from "./reducers/settingsReducer"; +let currentSettings: SettingsState | undefined = undefined; store.subscribe(() => { - saveState(store.getState()); + const prevSettings = currentSettings; + currentSettings = store.getState().settings; + + // Write to local-storage only when settings have changed. + if (prevSettings !== currentSettings) { + saveState(store.getState()); + } }); ReactDOM.render( diff --git a/ui/src/reducers/settingsReducer.ts b/ui/src/reducers/settingsReducer.ts index 50c88aa..96df2c1 100644 --- a/ui/src/reducers/settingsReducer.ts +++ b/ui/src/reducers/settingsReducer.ts @@ -9,7 +9,8 @@ export enum ThemePreference { Always, Never, } -interface SettingsState { + +export interface SettingsState { pollInterval: number; themePreference: ThemePreference; }