Skip to content

Commit

Permalink
Clean up store.
Browse files Browse the repository at this point in the history
  • Loading branch information
tdilauro committed Jun 26, 2024
1 parent 588a6ec commit 42a199b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 31 deletions.
6 changes: 1 addition & 5 deletions src/components/ContextProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ export default class ContextProvider extends React.Component<

constructor(props) {
super(props);
this.store =
props.store ??
buildStore({
csrfToken: props.csrfToken,
});
this.store = props.store ?? buildStore();
this.admin = new Admin(props.roles || [], props.email || null);
this.pathFor = (collectionUrl: string, bookUrl: string, tab?: string) => {
let path = "/admin/web";
Expand Down
4 changes: 1 addition & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ class CirculationAdmin {

const queryClient = new QueryClient();

const store = buildStore({
csrfToken: config.csrfToken,
});
const store = buildStore();
const appElement = "opds-catalog";
const app = config.settingUp ? (
<Provider store={store}>
Expand Down
25 changes: 2 additions & 23 deletions src/store.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { configureStore, Store } from "@reduxjs/toolkit";
import { configureStore } from "@reduxjs/toolkit";

// import { apiSlice } from "./features/admin/admin-api-slice";
import catalogReducers from "@thepalaceproject/web-opds-client/lib/reducers/index";
import { State as CatalogState } from "@thepalaceproject/web-opds-client/lib/state";
import bookEditorSlice from "./features/book/bookEditorSlice";
Expand All @@ -11,35 +10,15 @@ export interface CombinedState {
catalog: CatalogState;
}

type BuildStoreArgs = {
initialState?: CombinedState;
csrfToken?: string;
};

export type ThunkExtraArgument = {
csrfToken: string;
};

/** Build a redux store with reducers specific to the admin interface
as well as reducers from web-opds-client. */
export default function buildStore({
initialState,
csrfToken,
}: BuildStoreArgs = {}) {
// console.log("buildStore", initialState, csrfToken);
export default function buildStore(initialState?: CombinedState) {
return configureStore({
reducer: {
editor: editorReducers,
catalog: catalogReducers,
bookEditor: bookEditorSlice,
// [apiSlice.reducerPath]: apiSlice.reducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
thunk: {
extraArgument: { csrfToken: "...csrfToken-text-here..." },
},
}), // .concat(apiSlice.middleware),
preloadedState: initialState,
devTools: process.env.NODE_ENV !== "production",
});
Expand Down

0 comments on commit 42a199b

Please sign in to comment.