diff --git a/package.json b/package.json index 9a84d18..3910c8a 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@types/react-modal": "^3.10.5", "@types/react-redux": "^7.1.5", "@types/reactstrap": "^8.4.2", + "@types/redux-persist": "^4.3.1", "@types/wavesurfer.js": "^3.2.0", "@types/webpack-env": "^1.14.1", "@typescript-eslint/eslint-plugin": "^2.2.0", @@ -76,6 +77,7 @@ "react-redux": "^7.1.3", "reactstrap": "^8.4.1", "redux": "^4.0.4", + "redux-persist": "^6.0.0", "resolve": "1.12.0", "resolve-url-loader": "3.1.0", "sass-loader": "7.2.0", diff --git a/src/rootReducer.ts b/src/rootReducer.ts index 215e461..71b6575 100644 --- a/src/rootReducer.ts +++ b/src/rootReducer.ts @@ -1,5 +1,9 @@ import { combineReducers } from "@reduxjs/toolkit"; +import { persistReducer, PersistConfig } from "redux-persist"; +import webStorage from "redux-persist/lib/storage"; +import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2"; + import ShowplanReducer from "./showplanner/state"; import MixerReducer from "./mixer/state"; import BroadcastReducer from "./broadcast/state"; @@ -20,4 +24,13 @@ const rootReducer = combineReducers({ export type RootState = ReturnType; -export default rootReducer; +const persistenceConfig: PersistConfig = { + key: "root", + storage: webStorage, + whitelist: ["settings"], + stateReconciler: autoMergeLevel2 +}; + +const persistedReducer = persistReducer(persistenceConfig, rootReducer); + +export default persistedReducer; diff --git a/src/store.ts b/src/store.ts index 1ab7278..4dbd013 100644 --- a/src/store.ts +++ b/src/store.ts @@ -6,6 +6,7 @@ import { mixerKeyboardShortcutsMiddleware, } from "./mixer/state"; import { tabSyncMiddleware } from "./optionsMenu/state"; +import { persistStore } from "redux-persist"; const store = configureStore({ reducer: rootReducer, @@ -24,6 +25,8 @@ if (process.env.NODE_ENV === "development" && module.hot) { }); } +export const persistor = persistStore(store); + export type AppDispatch = typeof store.dispatch; export type AppThunk = ThunkAction>; export default store; diff --git a/yarn.lock b/yarn.lock index 1d66fa8..71fc75b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1531,6 +1531,13 @@ "@types/react" "*" popper.js "^1.14.1" +"@types/redux-persist@^4.3.1": + version "4.3.1" + resolved "https://registry.yarnpkg.com/@types/redux-persist/-/redux-persist-4.3.1.tgz#aa4c876859e0bea5155e5f7980e5b8c4699dc2e6" + integrity sha1-qkyHaFngvqUVXl95gOW4xGmdwuY= + dependencies: + redux-persist "*" + "@types/resolve@0.0.8": version "0.0.8" resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194" @@ -9011,6 +9018,11 @@ redux-immutable-state-invariant@^2.1.0: invariant "^2.1.0" json-stringify-safe "^5.0.1" +redux-persist@*, redux-persist@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/redux-persist/-/redux-persist-6.0.0.tgz#b4d2972f9859597c130d40d4b146fecdab51b3a8" + integrity sha512-71LLMbUq2r02ng2We9S215LtPu3fY0KgaGE0k8WRgl6RkqxtGfl7HUozz1Dftwsb0D/5mZ8dwAaPbtnzfvbEwQ== + redux-thunk@^2.3.0: version "2.3.0" resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622"