App.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { combineReducers, configureStore } from '@reduxjs/toolkit';
  2. import { Router, Route, Switch } from 'react-router-dom';
  3. import { createBrowserHistory } from "history";
  4. import { Provider } from 'react-redux';
  5. import { promiseReducer, frontEndReducer, cartReducer, actionRestoreCart, goodsApi, cartGoodsApi } from './reducers';
  6. import { CEditableGood, CGood, CGoodsList, CLoginForm, CMainAppBar, COrder, COrdersList, CUser } from "./Components";
  7. import { CLogout } from './Components';
  8. import { CSidebar } from './Components/Sidebar';
  9. import { CRootCats } from './Components';
  10. import './App.css';
  11. import { CCategory } from './Components/Category';
  12. import { categoryApi } from './reducers/categoryReducer';
  13. import { ordersApi } from './reducers/ordersReducer';
  14. import { CCart } from './Components/Cart';
  15. import { authApiReducer, authReducer, authApiReducerPath, loginApi, authReducerPath } from './reducers';
  16. import storage from "redux-persist/lib/storage";
  17. import {
  18. persistReducer, persistStore, FLUSH,
  19. REHYDRATE,
  20. PAUSE,
  21. PERSIST,
  22. PURGE,
  23. REGISTER,
  24. } from 'redux-persist';
  25. import { EditPost } from './Test/drop';
  26. import { FileDropZone } from './Components/FileDropZone';
  27. export const history = createBrowserHistory();
  28. const rootReducer = combineReducers({
  29. [authReducerPath]: persistReducer({ key: authReducerPath, storage }, authReducer),
  30. [authApiReducerPath]: authApiReducer,
  31. //[categoryApi.reducerPath]: persistReducer({ key: categoryApi.reducerPath, storage }, categoryApi.reducer),
  32. //[goodsApi.reducerPath]: persistReducer({ key: goodsApi.reducerPath, storage }, goodsApi.reducer),
  33. //[ordersApi.reducerPath]: persistReducer({ key: ordersApi.reducerPath, storage }, ordersApi.reducer),
  34. [categoryApi.reducerPath]: categoryApi.reducer,
  35. [goodsApi.reducerPath]: goodsApi.reducer,
  36. [ordersApi.reducerPath]: ordersApi.reducer,
  37. [cartGoodsApi.reducerPath]: cartGoodsApi.reducer,
  38. promise: promiseReducer,
  39. frontend: frontEndReducer,
  40. cart: cartReducer,
  41. });
  42. export const store = configureStore({
  43. middleware: (getDefaultMiddleware) => [
  44. ...getDefaultMiddleware({ serializableCheck: { ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER] } }),
  45. categoryApi.middleware,
  46. goodsApi.middleware,
  47. ordersApi.middleware,
  48. loginApi.middleware,
  49. cartGoodsApi.middleware],
  50. reducer: rootReducer
  51. });
  52. store.subscribe(() => console.log(store.getState()))
  53. /*const persistor = */persistStore(store)
  54. //store.dispatch(actionAuthLogin(localStorage.authToken));
  55. //store.dispatch(actionRootCats());
  56. store.dispatch(actionRestoreCart());
  57. const NotFound = () =>
  58. <div>
  59. <h1>404 not found</h1>
  60. </div>
  61. const Main = () =>
  62. <div>
  63. <h1>Main page</h1>
  64. </div>
  65. //<EditPost onSave={post => console.log(post)}/>
  66. function App() {
  67. return (
  68. <>
  69. <Router history={history}>
  70. <Provider store={store}>
  71. <div className="App">
  72. <CMainAppBar />
  73. <CSidebar menuComponent={() => <CRootCats />} />
  74. <Switch>
  75. <Route path="/" component={Main} exact />
  76. <Route path="/orders" component={COrdersList} />
  77. <Route path="/goods" component={CGoodsList} />
  78. <Route path="/good/:_id" component={CGood} />
  79. <Route path="/editgood/:_id" component={CEditableGood} />
  80. <Route path="/category/:_id" component={CCategory} />
  81. <Route path="/order/:_id" component={COrder} />
  82. <Route path="/cart" component={CCart} />
  83. <Route path="/login" component={CLoginForm} />
  84. <Route path="/user/:_id" component={CUser} />
  85. <Route path="/user" component={CUser} />
  86. <Route path="/logout" component={CLogout} />
  87. <Route path="*" component={NotFound} />
  88. </Switch>
  89. </div>
  90. </Provider>
  91. </Router>
  92. </>
  93. );
  94. }
  95. export default App;