index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import * as action from '../../actions'
  2. import plugPic from '../../assets/default.png'
  3. import { useState, useEffect, useCallback } from 'react';
  4. import { connect } from 'react-redux';
  5. import { Link } from 'react-router-dom';
  6. import { backendURL } from '../../App';
  7. import { useDropzone } from 'react-dropzone'
  8. import { faPlus, faBan, faSignOutAlt, faUpload} from "@fortawesome/free-solid-svg-icons";
  9. import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
  10. const LogoutBtn = ({ onLogout }) =>
  11. <Link
  12. to='/login'
  13. className='sidebar__link highlightRed'
  14. onClick={() => onLogout()}
  15. >LOG-OUT <FontAwesomeIcon icon={faSignOutAlt}/></Link>
  16. //export const LogoutBtnConnect = connect(null, { onLogout: action.actionAuthLogout })(LogoutBtn)
  17. export const LogoutBtnConnect = connect(null, { onLogout: action.actionFullLogout })(LogoutBtn)
  18. const ProfileWindow = ({ user }) => {
  19. let [userInfo, setUserInfo] = useState(user.payload)
  20. useEffect(() => setUserInfo(user.payload), [user, userInfo])
  21. return (
  22. <section >
  23. <h3>{userInfo?.login || 'user'}</h3>
  24. {userInfo?.avatar?.url ?
  25. <img src={backendURL + '/' + userInfo?.avatar?.url} alt='avatar'/> :
  26. <img src={plugPic} alt='avatar' />}
  27. </section>
  28. )
  29. }
  30. export const ProfileWindowConnect = connect(state => ({ user: state.promise.userData || {} }))(ProfileWindow)
  31. const ProfileWindowDropzone = ({ onLoad }) => {
  32. const onDrop = useCallback(acceptedFiles => {
  33. if(acceptedFiles[0].type === 'image/png' || acceptedFiles[0].type === 'image/jpeg') onLoad(acceptedFiles[0])
  34. }, [onLoad])
  35. const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop })
  36. return (
  37. <div {...getRootProps()}
  38. className='sidebar__profile'
  39. style={isDragActive ? { backgroundColor: '#0e6147' } : { backgroundColor: 'transparent' }}
  40. >
  41. <input {...getInputProps()} />
  42. <ProfileWindowConnect />
  43. <small className='lightText'>{isDragActive ? '...drop here' : 'change avatar'}</small>
  44. </div>
  45. )
  46. }
  47. export const ProfileWindowDropzoneConnect = connect(null, { onLoad: action.actionUploadAvatar })(ProfileWindowDropzone)
  48. const UserTracksBtn = ({ userId }) => {
  49. let [_id, setId] = useState()
  50. useEffect(() => setId(userId), [userId])
  51. return (<Link to={`/player/tracks/:${_id}`} className='sidebar__link highlightYellow'>UPLOADS <FontAwesomeIcon icon={faUpload}/></Link>)
  52. }
  53. export const UserTracksBtnConnect = connect(state => ({ userId: state.promise.userData?.payload?._id || '' }))(UserTracksBtn)
  54. const PlaylistAdd = ({ addPlaylist }) => {
  55. let [clicked, setClicked] = useState(false)
  56. let [name, setName] = useState()
  57. return (
  58. <div>
  59. {
  60. !clicked ?
  61. <button
  62. className='sidebar__button highlightPaleGreen'
  63. onClick={() => setClicked(true)}
  64. >NEW PLAYLIST</button>
  65. :
  66. <div className='sidebar__addpanel'>
  67. <input
  68. placeholder='NEW PLATLIST NAME'
  69. value={name}
  70. onChange={(e) => setName(e.target.value)}
  71. />
  72. <div className='sidebar__addpanel btnWrapper'>
  73. <button
  74. disabled={!name}
  75. className='highlightGreen'
  76. onClick={() => { addPlaylist(name); setClicked(false); setName(''); }}
  77. ><FontAwesomeIcon icon={faPlus} /></button>
  78. <button
  79. className='highlightRed'
  80. onClick={() => { setClicked(false); setName('') }}
  81. ><FontAwesomeIcon icon={faBan} /></button>
  82. </div>
  83. </div>
  84. }
  85. </div>
  86. )
  87. }
  88. export const PlaylistAddConnect = connect(null, { addPlaylist: action.actionAddPlaylist })(PlaylistAdd)
  89. const Playlists = ( { playlists }) => {
  90. return (
  91. <div>
  92. {
  93. playlists?.payload ? playlists.payload.map(item => {
  94. return (<Link key={item._id} className='sidebar__link' to={`/player/playlist/:${item._id}`}>{item.name}</Link> )
  95. }).reverse() : ''
  96. }
  97. </div>
  98. )
  99. }
  100. export const PlaylistsConnect = connect(state => ({ playlists: state.promise.userPlaylists || {} }))(Playlists)