userPage.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import React, {useState, useEffect} from 'react';
  2. import {Link} from 'react-router-dom';
  3. import {Provider, connect} from 'react-redux';
  4. import { actionUsersPlaylists } from '../store/promiseReducer';
  5. import { actionFullSetPlaylist } from '../store/playerReducer';
  6. import { store } from '../store/store';
  7. import image from '../images/card.png';
  8. import Modal from 'react-bootstrap/Modal';
  9. import Button from 'react-bootstrap/Button';
  10. import {CreatePlaylist} from './createPlaylist'
  11. import { Header } from './header';
  12. // function sendForm (url, data) {
  13. // fetch(`http://player-api/api/${url}`, {
  14. // method: 'POST',
  15. // body: data,
  16. // headers: {
  17. // ...(localStorage.authToken ? {"Authorization": "Bearer " + localStorage.authToken} : {})
  18. // },
  19. // }).then(res => res.json())
  20. // .then(data => {
  21. // if(data.token) {
  22. // console.log(data)
  23. // return data
  24. // } else {
  25. // //console.log(data.login[0]);
  26. // }
  27. // })
  28. // }
  29. const Playlist = ({playlist: {id, user_id, name, photo, description} = {}}) =>
  30. <div className="col-sm-3">
  31. <Link className="card" to= {`/playlist/${id}`} onClick={() => store.dispatch(actionFullSetPlaylist({id, user_id, name, photo, description}) )}>
  32. <img src={photo || image} className="card-img-top" alt="..."/>
  33. <div className="card-body">
  34. <h5 className="card-title"> {name}</h5>
  35. <p className="card-text">{description? description : '.' }</p>
  36. <button className="btn btn-primary" >Go somewhere</button>
  37. </div>
  38. </Link>
  39. </div>
  40. export const UsersPlaylistsAll = ({playlists= []}) =>
  41. <div className='RootCategories row'>
  42. {playlists.map((playlist, i) => <Playlist key={i} playlist={playlist}/>)}
  43. </div>
  44. const СUsersPlaylists = connect(state => ({playlists: state.promise.usersPlaylists?.payload?.playlists|| []}), )(UsersPlaylistsAll);
  45. function MyVerticallyCenteredModal(props) {
  46. return (
  47. <Modal
  48. {...props}
  49. size="lg"
  50. aria-labelledby="contained-modal-title-vcenter"
  51. centered
  52. >
  53. {/* <Modal.Header closeButton> */}
  54. {/* <Modal.Title id="contained-modal-title-vcenter">
  55. Create new Playlist
  56. </Modal.Title> */}
  57. {/*</Modal.Header> */}
  58. <Modal.Body >
  59. <CreatePlaylist props={props}/>
  60. </Modal.Body>
  61. {/* <Modal.Footer>
  62. <Button variant="outline-danger" onClick={props.onHide}>Create</Button>
  63. </Modal.Footer> */}
  64. </Modal>
  65. );
  66. }
  67. export const UserPage = () => {
  68. let id = store.getState().auth.user.id;
  69. const getAnswer = async () => {
  70. await store.dispatch(actionUsersPlaylists(id));
  71. };
  72. useEffect(() => {
  73. getAnswer();
  74. }, []);
  75. const [modalShow, setModalShow] = React.useState(false);
  76. return(<>
  77. <Header/>
  78. <div className='d-flex container align-items-center justify-content-center'>
  79. <div className='col'>
  80. <img className='col-sm-3' alt='...' src={image}/>
  81. </div>
  82. <div className='col'>
  83. <h3>{store.getState().auth.user.name}</h3>
  84. <a href='/change'>Edit Profile</a>
  85. </div>
  86. </div>
  87. <Button variant="primary" onClick={() => setModalShow(true)}>
  88. Create new Playlist
  89. </Button>
  90. <MyVerticallyCenteredModal
  91. show={modalShow}
  92. onHide={() => setModalShow(false)}
  93. />
  94. <h3>My playlists:</h3>
  95. <СUsersPlaylists/>
  96. </>)
  97. }