import { createAction, createAsyncAction } from './utils'; import { createReducer } from '@reduxjs/toolkit'; const actions = { refresh: 'LOCAL_STORAGE_REFRESH' }; export const getConfigValue = createAsyncAction((dispatch, getState, config, key) => { const payload = { key: key, value: JSON.parse(localStorage.getItem(key)) || undefined }; return dispatch(refreshConfigValue(payload)); }); export const setConfigValue = createAsyncAction((dispatch, getState, config, key, value) => { localStorage.setItem(key, JSON.stringify(value)); return dispatch(refreshConfigValue({ key: key, value: value })); }); export const refreshConfigValue = createAction(actions.refresh, (payload) => { return payload; }); export default createReducer({}, (builder) => { builder.addDefaultCase((state, action) => { state[action.payload?.key] = action.payload?.value; }); });