mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-19 19:25:52 +08:00
25 lines
638 B
TypeScript
25 lines
638 B
TypeScript
|
import { AppState } from "./store";
|
||
|
|
||
|
const LOCAL_STORAGE_KEY = "asynqmon:state";
|
||
|
|
||
|
export function loadState(): AppState | undefined {
|
||
|
try {
|
||
|
const serializedState = localStorage.getItem(LOCAL_STORAGE_KEY);
|
||
|
if (serializedState === null) {
|
||
|
return undefined;
|
||
|
}
|
||
|
return JSON.parse(serializedState);
|
||
|
} catch (err) {
|
||
|
return undefined;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|