DropZoneAvatar.jsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {useDropzone} from 'react-dropzone';
  2. import { useEffect} from 'react';
  3. import { connect } from 'react-redux';
  4. import { Avatar } from '@mui/material';
  5. import { backendURL } from '../../helpers/gql';
  6. import { actionSetUserAvatar } from '../../actions/actionsMedia';
  7. import Camera from './icons8_camera.png';
  8. import { Drop } from '../ChatInfoModal/ChatInfoModal.style';
  9. import { AvatarWrap, AvatarOverlay } from './DropZoneAvatar.style';
  10. import { BadgeComponent } from '../UserEditorModal/UserEditorModal.style';
  11. import Photo from "../UserEditorModal/icons8photo.png";
  12. // import { actionSetUserAvatar } from './UserMenu';
  13. const DropAvatarComponent = ({url}) => {
  14. return(
  15. <AvatarWrap>
  16. <Avatar
  17. src={url}
  18. sx={{width: "75px", height: "75px"}}
  19. />
  20. <AvatarOverlay>
  21. <img src={Camera}/>
  22. </AvatarOverlay>
  23. </AvatarWrap>
  24. )
  25. }
  26. const DropAvatarPopupComponent = () => {
  27. return(
  28. <div style={{
  29. width: "100%",
  30. height: "30px",
  31. backgroundColor: "grey",
  32. opacity: "0.5",
  33. display: "flex",
  34. justifyContent: "center",
  35. alignItem: "center",
  36. cursor: "pointer"
  37. }}>
  38. <img style={{height: "26px"}} src={Camera}/>
  39. </div>
  40. )
  41. }
  42. export default function DropZoneAvatar({onLoad, component, url }) {
  43. const dropMap = {
  44. dropAvatarComponent: <DropAvatarComponent url={url}/>,
  45. dropAvatarPopupComponent: <DropAvatarPopupComponent/>,
  46. dropAvatarBadge: <BadgeComponent><img src={Photo}/></BadgeComponent>
  47. }
  48. const {acceptedFiles, getRootProps, getInputProps} = useDropzone({
  49. noDrag: true,
  50. multiple: false,
  51. accept: 'image/*'
  52. });
  53. useEffect(()=>{
  54. console.log(acceptedFiles)
  55. acceptedFiles[0] && onLoad(acceptedFiles[0])
  56. }, [acceptedFiles])
  57. return (
  58. <section className="container" >
  59. <div
  60. {...getRootProps({className: 'dropzone'})}>
  61. <input {...getInputProps()} />
  62. {dropMap[component]}
  63. </div>
  64. </section>
  65. );
  66. }