feat(gui): Preserve global state across page reloads (#48)

This commit is contained in:
binarybaron 2024-08-29 13:38:11 +02:00 committed by GitHub
parent c7c7cf1886
commit d913206062
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 35 additions and 11 deletions

View file

@ -1,9 +1,28 @@
import { configureStore } from "@reduxjs/toolkit";
import { combineReducers, configureStore } from "@reduxjs/toolkit";
import { persistReducer, persistStore } from "redux-persist";
import sessionStorage from "redux-persist/lib/storage/session";
import { reducers } from "store/combinedReducer";
// We persist the redux store in sessionStorage
// The point of this is to preserve the store across reloads while not persisting it across GUI restarts
//
// If the user reloads the page, while a swap is running we want to
// continue displaying the correct state of the swap
const persistConfig = {
key: "gui-global-state-store",
storage: sessionStorage,
};
const persistedReducer = persistReducer(
persistConfig,
combineReducers(reducers),
);
export const store = configureStore({
reducer: reducers,
reducer: persistedReducer,
});
export const persistor = persistStore(store);
export type AppDispatch = typeof store.dispatch;
export type RootState = ReturnType<typeof store.getState>;