App.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import './App.scss';
  2. import React, {useState,useEffect, useMemo, useRef} from 'react';
  3. import 'bootstrap/dist/css/bootstrap.min.css';
  4. import {Router, Route, Link, Redirect, Switch} from 'react-router-dom';
  5. import createHistory from "history/createBrowserHistory";
  6. //import thunk from 'redux-thunk';
  7. import {Provider, connect} from 'react-redux';
  8. //import {createStore, combineReducers, applyMiddleware} from 'redux';
  9. import { store } from './store/store';
  10. import { actionAllPlaylists } from './store/promiseReducer';
  11. import { actionFullSetPlaylist } from './store/playerReducer';
  12. import {CLoginForm} from './components/authorization'
  13. import {CRegisterForm} from './components/authRegistration'
  14. import {CreatePlaylist} from './components/createPlaylist'
  15. import { Header } from './components/header';
  16. import { UserPage, UsersPlaylistsAll } from './components/userPage';
  17. import {PlaylistById} from './components/playlistById';
  18. import { BrowserRouter } from "react-router-dom";
  19. export let history = createHistory()
  20. store.subscribe(() => console.log(store.getState()));
  21. store.dispatch(actionAllPlaylists());
  22. const Playlist = ({playlist: {id, user_id, name, photo, description} = {}}) =>
  23. <div className="col-sm-3">
  24. <Link className="card" to= {`/playlist/${id}`} onClick={() => store.dispatch(actionFullSetPlaylist({id, user_id, name, photo, description}) )}>
  25. <img src={photo} className="card-img-top" alt="..."/>
  26. <div className="card-body">
  27. <h5 className="card-title"> {name}</h5>
  28. <p className="card-text">{description? description : '.' }</p>
  29. <button className="btn btn-primary" >Go somewhere</button>
  30. </div>
  31. </Link>
  32. </div>
  33. const PlaylistsAll = ({playlists= []}) =>
  34. <div className='RootCategories row'>
  35. {playlists.map((playlist, i) => <Playlist key={i} playlist={playlist}/>)}
  36. </div>
  37. const СAllPlaylists = connect(state => ({playlists: state.promise.allPlaylists?.payload?.playlists?.data || []}), )(PlaylistsAll);
  38. const CPlaylistById = connect(state => ({playlist: state.promise.plstById?.payload || {}}), )(PlaylistById);
  39. //const СUserPlaylists = connect(state => ({playlists: state.promise.usersPlaylists?.payload?.playlists?.data || []}), )(UsersPlaylistsAll);
  40. const Aside = ({children}) =>
  41. <div>
  42. <Header/>
  43. <СAllPlaylists/>
  44. </div>
  45. const Main = ({children}) =>
  46. <main className='bg-dark text-white'>
  47. <BrowserRouter history = {history}>
  48. <Content>
  49. <Switch>
  50. {store.getState().auth?.token && <Redirect from='/login' to={'/user'} exact />}
  51. {store.getState().auth?.token && <Redirect from='/register' to={'/user'} exact />}
  52. {!store.getState().auth?.token && <Redirect from='/user' to={'/login'} exact />}
  53. <Route path={'/login'} component={CLoginForm} />
  54. <Route path={'/register'} component={CRegisterForm}/>
  55. <Route path={'/allplaylists'} component={Aside}/>
  56. <Route path={'/playlist'} component={CPlaylistById} />
  57. <Route path={'/create'} component={CreatePlaylist} />
  58. <Route path={'/user'} component={UserPage} />
  59. {/* <Route path={'/'} component={Header} /> */}
  60. </Switch>
  61. {/* {children} */}
  62. </Content>
  63. </BrowserRouter>
  64. </main>
  65. // const Main = ({children}) =>
  66. // <main className='bg-dark text-white'>
  67. // <Router history = {history}>
  68. // <Content>
  69. // <Switch>
  70. // {store.getState().auth?.token && <Redirect from='/login' to={'/user'} exact />}
  71. // {store.getState().auth?.token && <Redirect from='/register' to={'/user'} exact />}
  72. // {!store.getState().auth?.token && <Redirect from='/user' to={'/login'} exact />}
  73. // <Route path={'/login'} component={CLoginForm} />
  74. // <Route path={'/register'} component={CRegisterForm}/>
  75. // <Route path={'/allplaylists'} component={Aside}/>
  76. // <Route path={'/playlist'} component={CPlaylistById} />
  77. // <Route path={'/create'} component={CreatePlaylist} />
  78. // <Route path={'/user'} component={UserPage} />
  79. // {/* <Route path={'/'} component={Header} /> */}
  80. // </Switch>
  81. // {/* {children} */}
  82. // </Content>
  83. // </Router>
  84. // </main>
  85. const Content = ({children}) =>
  86. <section className='Content'>
  87. {children}
  88. </section>
  89. function App() {
  90. return (
  91. <Router history={history}>
  92. <Provider store ={store}>
  93. {/* <Header/> */}
  94. <Main/>
  95. </Provider>
  96. </Router>
  97. );
  98. }
  99. const Footer = ({children}) =>
  100. <footer>
  101. {/* <Logo/> */}
  102. {children}
  103. </footer>
  104. export default App;