mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-10-03 02:32:00 +08:00
Save task-rows-per-page as user settings
This commit is contained in:
@@ -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 {};
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user