cleaned up the routing

This commit is contained in:
Luke Berndt
2023-03-24 09:14:58 -04:00
parent ae6cabc7d1
commit a5888e412c
21 changed files with 68 additions and 877 deletions

View File

@@ -2,11 +2,11 @@ import React from 'react';
import { createRoot } from 'react-dom/client';
import { BrowserRouter } from "react-router-dom";
import { Provider } from 'react-redux'
import configureStore from './redux-router/configureStore'
import setupStore from './redux-router/configureStore'
import App from "./app"
const store = configureStore(/* provide initial state if any */)
const store = setupStore(/* provide initial state if any */)
const container = document.getElementById('root');
const root = createRoot(container);

View File

@@ -1,31 +1,22 @@
// https://github.com/supasate/connected-react-router
// configureStore.js
import { configureStore } from '@reduxjs/toolkit'
import { apiSlice } from "../features/api/apiSlice"
import callPlayerSlice from "../features/callPlayer/callPlayerSlice"
import { callsReducer } from "../features/calls/callsSlice"
import { createBrowserHistory } from 'history'
import { applyMiddleware, compose, createStore } from 'redux'
import { createRouterMiddleware } from '@lagunovsky/redux-react-router'
//import { routerMiddleware } from 'connected-react-router'
import createRootReducer from './reducers'
import { apiSlice } from '../features/api/apiSlice'
const setupStore = (preloadedState) => {
const store = configureStore({
reducer: {
callPlayer: callPlayerSlice,
calls: callsReducer,
[apiSlice.reducerPath]: apiSlice.reducer,
},
middleware: (getDefaultMiddleware) =>
// adding the api middleware enables caching, invalidation, polling and other features of `rtk-query`
getDefaultMiddleware().concat(apiSlice.middleware),
preloadedState,
})
import thunk from 'redux-thunk';
export const history = createBrowserHistory()
export default function configureStore(preloadedState) {
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(
createRootReducer(history), // root reducer with router state
preloadedState,
composeEnhancers(
applyMiddleware(
createRouterMiddleware(history), // for dispatching history actions
thunk,
apiSlice.middleware,
// ... other middlewares ...
),
),
)
return store
}
}
export default setupStore;

View File

@@ -1,15 +0,0 @@
// from https://github.com/supasate/connected-react-router
import { combineReducers } from 'redux'
//import { connectRouter } from 'connected-react-router'
import { createRouterReducer } from '@lagunovsky/redux-react-router'
import {apiSlice} from "../features/api/apiSlice"
import callPlayerSlice from "../features/callPlayer/callPlayerSlice"
import { callsReducer } from "../features/calls/callsSlice"
export default (history) => combineReducers({
router: createRouterReducer(history),
callPlayer: callPlayerSlice,
calls: callsReducer,
[apiSlice.reducerPath]: apiSlice.reducer,
})