userPlaylists.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import React from 'react';
  2. import {Link} from 'react-router-dom';
  3. import { actionPlaylistById} from '../store/promiseReducer';
  4. import { actionFullSetPlaylist, actionFullSetTrack} from '../store/playerReducer';
  5. import { store } from '../store/store';
  6. import image from '../images/card.jpg';
  7. import {CreatePlaylist} from './createPlaylist';
  8. import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
  9. import {faHeadphonesSimple, faPlay, faPlus, faLock,} from "@fortawesome/free-solid-svg-icons";
  10. import Button from "react-bootstrap/Button";
  11. export const Playlist = ({playlist}) => {
  12. let link = (((window.location.href.split('/')[3]) === 'artists' || (window.location.href.split('/')[3]) === 'search') ? 'albums' : 'playlist');
  13. return(
  14. <div className="">
  15. <div className="me-4 mb-4 p-4 playlist-img-box rounded-5 position-relative"
  16. style={{backgroundImage: `url(${playlist.photo})`, backgroundSize: "cover", backgroundRepeat: "no-repeat", backgroundPosition: "center", width:250, height:250}}
  17. >
  18. <div className="playlist-grey-box"></div>
  19. <Link className="d-flex justify-content-between flex-wrap border-0 link-light position-relative text-decoration-none h6 text-wrap"
  20. to={`/${link}/${playlist.id}`} onClick={() => {
  21. store.dispatch(actionPlaylistById(playlist.id));
  22. }}>
  23. <span className="playlist-title w-75">{playlist.name}</span>
  24. {store.getState().auth?.user?.id === playlist.user_id && playlist.private === 1 ?
  25. <span>
  26. <FontAwesomeIcon icon={faLock}></FontAwesomeIcon>
  27. </span> : null
  28. }
  29. </Link>
  30. <Button variant="outline-light" className='rounded-5 position-absolute playlist-play-box' title='Play'>
  31. <FontAwesomeIcon className='' icon={faPlay}
  32. onClick={() => {
  33. store.dispatch(actionPlaylistById(playlist.id));
  34. setTimeout(() => {
  35. if(store.getState().promise?.plstById?.payload?.tracks) {
  36. let tracks = store.getState().promise?.plstById?.payload?.tracks;
  37. store.dispatch(actionFullSetPlaylist(tracks));
  38. store.dispatch(actionFullSetTrack(store.getState().player?.playlist[0]));
  39. }
  40. }
  41. , 500)
  42. }}
  43. />
  44. </Button>
  45. </div>
  46. </div>)
  47. }
  48. export const UsersPlaylistsAll = ({playlists}) => {
  49. const [modalShow, setModalShow] = React.useState(false);
  50. return (
  51. <>
  52. <div className="d-flex justify-content-between align-items-center py-3">
  53. <h3 className="text-uppercase"> <FontAwesomeIcon icon={faHeadphonesSimple} className="me-2"/>My playlists</h3>
  54. <Button variant="outline-success" title='Create playlist' onClick={() => setModalShow(true)}>
  55. <FontAwesomeIcon icon={faPlus} />
  56. </Button>
  57. <CreatePlaylist
  58. show={modalShow}
  59. onHide={() => setModalShow(false)}
  60. />
  61. </div>
  62. <div className='RootCategories d-flex justify-content-start flex-wrap'>
  63. {playlists.map((playlist, i) => <Playlist key={i} playlist={playlist}/>)}
  64. </div>
  65. </>)
  66. }