github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/ui/src/localStorage.ts (about)

     1  import { initialState as settingsInitialState } from "./reducers/settingsReducer"
     2  import { AppState } from "./store";
     3  
     4  const LOCAL_STORAGE_KEY = "asynqmon:state";
     5  
     6  export function loadState(): Partial<AppState> {
     7    try {
     8      const serializedState = localStorage.getItem(LOCAL_STORAGE_KEY);
     9      if (serializedState === null) {
    10        return {};
    11      }
    12      const savedState = JSON.parse(serializedState);
    13      return {
    14        settings: {
    15          ...settingsInitialState,
    16          ...(savedState.settings || {}),
    17        }
    18      }
    19    } catch (err) {
    20      console.log("loadState: could not load state ", err)
    21      return {};
    22    }
    23  }
    24  
    25  export function saveState(state: AppState) {
    26    try {
    27      const serializedState = JSON.stringify({ settings: state.settings });
    28      localStorage.setItem(LOCAL_STORAGE_KEY, serializedState);
    29    } catch (err) {
    30      console.error("saveState: could not save state: ", err);
    31    }
    32  }