App.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. let history = createHistory()
  19. store.subscribe(() => console.log(store.getState()));
  20. store.dispatch(actionAllPlaylists());
  21. const Playlist = ({playlist: {id, user_id, name, photo, description} = {}}) =>
  22. <div className="col-sm-3">
  23. <Link className="card" to= {`/playlist/${id}`} onClick={() => store.dispatch(actionFullSetPlaylist({id, user_id, name, photo, description}) )}>
  24. <img src={photo} className="card-img-top" alt="..."/>
  25. <div className="card-body">
  26. <h5 className="card-title"> {name}</h5>
  27. <p className="card-text">{description? description : '.' }</p>
  28. <button className="btn btn-primary" >Go somewhere</button>
  29. </div>
  30. </Link>
  31. </div>
  32. const PlaylistsAll = ({playlists= []}) =>
  33. <div className='RootCategories row'>
  34. {playlists.map((playlist, i) => <Playlist key={i} playlist={playlist}/>)}
  35. </div>
  36. const СAllPlaylists = connect(state => ({playlists: state.promise.allPlaylists?.payload?.playlists?.data || []}), )(PlaylistsAll);
  37. const CPlaylistById = connect(state => ({playlist: state.promise.plstById?.payload || {}}), )(PlaylistById);
  38. //const СUserPlaylists = connect(state => ({playlists: state.promise.usersPlaylists?.payload?.playlists?.data || []}), )(UsersPlaylistsAll);
  39. const Aside = ({children}) =>
  40. <div>
  41. <Header/>
  42. <СAllPlaylists/>
  43. </div>
  44. const Main = ({children}) =>
  45. <main className='bg-dark text-white'>
  46. <Router history = {createHistory()}>
  47. <Content>
  48. <Switch>
  49. {store.getState().auth?.token && <Redirect from='/login' to={'/user'} exact />}
  50. {store.getState().auth?.token && <Redirect from='/register' to={'/user'} exact />}
  51. {!store.getState().auth?.token && <Redirect from='/user' to={'/login'} exact />}
  52. <Route path={'/login'} component={CLoginForm} />
  53. <Route path={'/register'} component={CRegisterForm}/>
  54. <Route path={'/allplaylists'} component={Aside}/>
  55. <Route path={'/playlist'} component={CPlaylistById} />
  56. <Route path={'/create'} component={CreatePlaylist} />
  57. <Route path={'/user'} component={UserPage} />
  58. {/* <Route path={'/'} component={Header} /> */}
  59. </Switch>
  60. {/* {children} */}
  61. </Content>
  62. </Router>
  63. </main>
  64. const Content = ({children}) =>
  65. <section className='Content'>
  66. {children}
  67. </section>
  68. function App() {
  69. return (
  70. <Router history={history}>
  71. <Provider store ={store}>
  72. {/* <Header/> */}
  73. <Main/>
  74. </Provider>
  75. </Router>
  76. );
  77. }
  78. const Footer = ({children}) =>
  79. <footer>
  80. {/* <Logo/> */}
  81. {children}
  82. </footer>
  83. export default App;