App.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import React, { useState } from 'react';
  2. import { Router, Route, Switch, useParams } from 'react-router-dom';
  3. import createHistory from "history/createBrowserHistory";
  4. import { createStore, combineReducers, applyMiddleware } from 'redux';
  5. import { Provider, connect, useSelector } from 'react-redux';
  6. import thunk from 'redux-thunk';
  7. import './App.css';
  8. import { authReducer, promiseReducer, actionAuthLogin } from './reducers';
  9. import { CLoginForm, GoodExample, GoodsList, goodsExample, Category, exampleCategory, OrderGood, exampleOrderGood, Order, exampleOrder, OrderList, exampleOrderList, exampleOrderGoodsList, OrderGoodsList } from "./Components";
  10. import { MainAppBar } from './Components';
  11. import { CLogout } from './Components';
  12. import { Sidebar } from './Components/Sidebar';
  13. export const history = createHistory()
  14. console.log(useParams)
  15. const store = createStore(combineReducers({ promise: promiseReducer, auth: authReducer }), applyMiddleware(thunk));
  16. store.subscribe(() => console.log(store.getState()))
  17. //store.dispatch(actionRootCats())
  18. //store.dispatch(actionAuthLogin(localStorage.authToken));
  19. /*const CCatMenu = connect(state => ({ cats: state.promise?.rootCats?.payload || [] }), { onLogin: actionFullLogin })(CatMenu)
  20. const CLoginForm = connect(null, { onLogin: actionFullLogin })(LoginForm)*/
  21. store.dispatch(actionAuthLogin(localStorage.authToken));
  22. const NotFound = () =>
  23. <div>
  24. <h1>404 not found</h1>
  25. </div>
  26. const Test = () => {
  27. let state = useSelector(state => state);
  28. let stateAuth = state.auth;
  29. let [auth, setAuth] = useState('');
  30. if (stateAuth != auth) {
  31. auth = auth;
  32. }
  33. return <div />
  34. }
  35. function App() {
  36. return (
  37. <>
  38. <Router history={history}>
  39. <Provider store={store}>
  40. <Test />
  41. <div className="App">
  42. <MainAppBar />
  43. <Sidebar menuComponent={() => <div>TEST!!!!!!</div>} />
  44. <Switch>
  45. {/*<Route path="/" component={Main} exact />*/}
  46. <Route path="/login" component={CLoginForm} />
  47. <Route path="/logout" component={CLogout} />
  48. <Route path="*" component={NotFound} />
  49. </Switch>
  50. {/*<CCatMenu />
  51. <LoginForm onLogin={(l, p) => console.log(l, p)} />
  52. <CLoginForm />
  53. <MyLink to="/" activeClassName='activeLink'>Главная</MyLink>
  54. <MyLink to="/aboutus" activeClassName='activeLink'>О нас</MyLink>
  55. <MyLink to="/add/2/3" activeClassName='activeLink'>2 + 3</MyLink>
  56. <MyLink to="/add/20/50" activeClassName='activeLink'>20 + 50</MyLink>
  57. <h1>Этот текст будет всегда в независимости от роутинга</h1>
  58. <Switch>
  59. <Route path="/" component={Main} exact />
  60. <Route path="/aboutus" component={AboutUs} />
  61. <Route path="/add/:a/:b" component={Add} />
  62. <Route path="*" component={NotFound} />
  63. </Switch>
  64. <h1>Роутинг выше</h1>*/}
  65. </div>
  66. </Provider>
  67. </Router>
  68. {/*
  69. <GoodsList goods={goodsExample} />
  70. <GoodExample />
  71. <Category category={exampleCategory} />
  72. <OrderGood orderGood={exampleOrderGood}/>
  73. <Order order={exampleOrder} />
  74. <OrderList orders={exampleOrderList} />
  75. <OrderGoodsList orderGoods={exampleOrderGoodsList} />
  76. */}
  77. </>
  78. );
  79. }
  80. {/* <div className="App">
  81. <header className="App-header">
  82. <img src={logo} className="App-logo" alt="logo" />
  83. <p>
  84. Edit <code>src/App.js</code> and save to reload.
  85. </p>
  86. <a
  87. className="App-link"
  88. href="https://reactjs.org"
  89. target="_blank"
  90. rel="noopener noreferrer"
  91. >
  92. Learn React
  93. </a>
  94. </header>
  95. </div>
  96. */}
  97. export default App;