App.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import 'antd/dist/antd.min.css'
  2. import './App.scss';
  3. import { Router, Route, Switch, Redirect } from 'react-router-dom';
  4. import createHistory from "history/createBrowserHistory";
  5. import { connect, Provider } from 'react-redux';
  6. import store from './redux/redux-store';
  7. import { Authorization } from './pages/Authorization';
  8. import { CPostsTapeMyFollowing } from './pages/PostsTapeMyFollowing';
  9. import HeaderComponent from './components/header/Header';
  10. import { CProfilePage } from './pages/ProfilePage';
  11. import { CAllPostsTape } from './pages/AllPostsTape';
  12. import { CCollectionPage } from './pages/CollectionPage';
  13. import { CSettingsPage } from './pages/SettingsPage';
  14. import { CEditPostPage } from './pages/EditPostPage';
  15. import { CPostOnePage } from './pages/PostOnePage';
  16. import { CRRoute } from './hoc/RRoute';
  17. import { FooterComponet } from './components/FooterComponent';
  18. import { useMediaQuery } from 'react-responsive';
  19. export const history = createHistory()
  20. const Main = ({ children }) =>
  21. <div className='Main'>{children}</div>
  22. const Content = ({ children }) =>
  23. <>{children}</>
  24. const AppContent = ({ isToken }) => {
  25. const isTabletDevice = useMediaQuery({
  26. query: "(max-width: 786px)"
  27. })
  28. return <Router history={history}>
  29. {!isToken
  30. ?
  31. <Switch>
  32. <Route path='/auth/:_id'
  33. component={Authorization} />
  34. <Redirect from='/*' to='/auth/login' />
  35. </Switch>
  36. :
  37. <Content>
  38. <HeaderComponent />
  39. <Main>
  40. <Switch>
  41. <Route path='/tape' component={CPostsTapeMyFollowing} />
  42. <Route path='/profile/:_id' component={CProfilePage} />
  43. <Route path='/edit/post/:_id' component={CEditPostPage} />
  44. <Route path='/my-settings' component={CSettingsPage} />
  45. <Route path='/all' component={CAllPostsTape} />
  46. <Route path='/my-collection' component={CCollectionPage} />
  47. <CRRoute path='/post/:id' component={CPostOnePage} />
  48. <Redirect from='/*' to='/tape' />
  49. </Switch>
  50. </Main>
  51. {isTabletDevice && <FooterComponet />}
  52. </Content >
  53. }
  54. </Router >
  55. }
  56. const CAppContent = connect(state => ({ isToken: state.auth?.token }))(AppContent)
  57. store.subscribe(() => console.log(store.getState()))
  58. function App() {
  59. return (
  60. <Provider store={store}>
  61. <CAppContent />
  62. </Provider>
  63. )
  64. }
  65. export default App;