index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. 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(() => {
  51. console.log('CHENG', userId)
  52. setId(userId)
  53. }, [userId])
  54. return (<Link to={`/player/tracks/:${_id}`} className='sidebar__link highlightYellow'>UPLOADS <FontAwesomeIcon icon={faUpload}/></Link>)
  55. }
  56. export const UserTracksBtnConnect = connect(state => ({ userId: state.promise.userData?.payload?._id || '' }))(UserTracksBtn)
  57. const PlaylistAdd = ({ addPlaylist }) => {
  58. let [clicked, setClicked] = useState(false)
  59. let [name, setName] = useState()
  60. return (
  61. <div>
  62. {
  63. !clicked ?
  64. <button
  65. className='sidebar__button highlightPaleGreen'
  66. onClick={() => setClicked(true)}
  67. >NEW PLAYLIST</button>
  68. :
  69. <div className='sidebar__addpanel'>
  70. <input
  71. placeholder='NEW PLATLIST NAME'
  72. value={name}
  73. onChange={(e) => setName(e.target.value)}
  74. />
  75. <div className='sidebar__addpanel btnWrapper'>
  76. <button
  77. disabled={!name}
  78. className='highlightGreen'
  79. onClick={() => { addPlaylist(name); setClicked(false); setName(''); }}
  80. ><FontAwesomeIcon icon={faPlus} /></button>
  81. <button
  82. className='highlightRed'
  83. onClick={() => { setClicked(false); setName('') }}
  84. ><FontAwesomeIcon icon={faBan} /></button>
  85. </div>
  86. </div>
  87. }
  88. </div>
  89. )
  90. }
  91. export const PlaylistAddConnect = connect(null, { addPlaylist: action.actionAddPlaylist })(PlaylistAdd)
  92. const Playlists = ( { playlists }) => {
  93. return (
  94. <div>
  95. {
  96. playlists?.payload ? playlists.payload.map(item => {
  97. return (
  98. <Link className='sidebar__link' to={`/player/playlist/:${item._id}`}>{item.name}</Link>
  99. )
  100. }).reverse() : ''
  101. }
  102. </div>
  103. )
  104. }
  105. export const PlaylistsConnect = connect(state => ({ playlists: state.promise.userPlaylists || {} }))(Playlists)