mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-19 11:15:53 +08:00
33 lines
890 B
TypeScript
33 lines
890 B
TypeScript
import { initialState as settingsInitialState } from "./reducers/settingsReducer"
|
|
import { AppState } from "./store";
|
|
|
|
const LOCAL_STORAGE_KEY = "asynqmon:state";
|
|
|
|
export function loadState(): Partial<AppState> {
|
|
try {
|
|
const serializedState = localStorage.getItem(LOCAL_STORAGE_KEY);
|
|
if (serializedState === null) {
|
|
return {};
|
|
}
|
|
const savedState = JSON.parse(serializedState);
|
|
return {
|
|
settings: {
|
|
...settingsInitialState,
|
|
...(savedState.settings || {}),
|
|
}
|
|
}
|
|
} catch (err) {
|
|
console.log("loadState: could not load state ", err)
|
|
return {};
|
|
}
|
|
}
|
|
|
|
export function saveState(state: AppState) {
|
|
try {
|
|
const serializedState = JSON.stringify({ settings: state.settings });
|
|
localStorage.setItem(LOCAL_STORAGE_KEY, serializedState);
|
|
} catch (err) {
|
|
console.error("saveState: could not save state: ", err);
|
|
}
|
|
}
|