Save task-rows-per-page as user settings

This commit is contained in:
Ken Hibino
2021-04-09 16:28:01 -07:00
parent f00f19d838
commit 33ac2d7316
9 changed files with 66 additions and 28 deletions

View File

@@ -1,16 +1,24 @@
import { initialState as settingsInitialState } from "./reducers/settingsReducer"
import { AppState } from "./store";
const LOCAL_STORAGE_KEY = "asynqmon:state";
export function loadState(): AppState | undefined {
export function loadState(): Partial<AppState> {
try {
const serializedState = localStorage.getItem(LOCAL_STORAGE_KEY);
if (serializedState === null) {
return undefined;
return {};
}
const savedState = JSON.parse(serializedState);
return {
settings: {
...settingsInitialState,
...(savedState.settings || {}),
}
}
return JSON.parse(serializedState);
} catch (err) {
return undefined;
console.log("loadState: could not load state ", err)
return {};
}
}