paper-ai-release-24-07-21/app/store/index.ts

53 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-01-21 23:08:25 +08:00
import { combineReducers, configureStore } from "@reduxjs/toolkit";
import { useDispatch, TypedUseSelectorHook, useSelector } from "react-redux";
import { persistReducer } from "redux-persist";
// import storage from "redux-persist/lib/storage";
import { authReducer } from "./slices/authSlice";
2024-02-08 10:31:29 +08:00
import { stateReducer } from "./slices/stateSlice";
2024-01-21 23:08:25 +08:00
import storage from "./customStorage";
import logger from "redux-logger";
const authPersistConfig = {
key: "chatapi",
storage: storage,
2024-01-29 13:35:24 +08:00
whitelist: [
"apiKey",
"referencesRedux",
"editorContent",
"upsreamUrl",
"systemPrompt",
],
2024-01-21 23:08:25 +08:00
};
2024-02-08 10:31:29 +08:00
const statePersistConfig = {
key: "state1",
storage: storage,
whitelist: [
"showPaperManagement",
"paperNumberRedux",
"contentUpdatedFromNetwork",
2024-02-08 23:06:35 +08:00
"isVip",
2024-02-12 20:55:14 +08:00
"language",
"isJumpToReference",
"isEvaluateTopicMatch",
2024-02-23 19:17:12 +08:00
"citationStyle",
2024-02-08 10:31:29 +08:00
],
};
2024-01-21 23:08:25 +08:00
const rootReducer = combineReducers({
auth: persistReducer(authPersistConfig, authReducer),
2024-02-08 10:31:29 +08:00
state: persistReducer(statePersistConfig, stateReducer),
2024-01-21 23:08:25 +08:00
});
export const store = configureStore({
reducer: rootReducer,
middleware: (getDefaultMiddleware) =>
2024-02-10 13:25:43 +08:00
getDefaultMiddleware({ serializableCheck: false }), //.concat(logger)
2024-01-21 23:08:25 +08:00
});
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
export const useAppDispatch = () => useDispatch<AppDispatch>();
2024-01-23 11:52:57 +08:00
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;