|
|
|
@@ -0,0 +1,109 @@ |
|
|
|
import React, { useRef, useState } from "react"; |
|
|
|
import PropTypes from "prop-types"; |
|
|
|
import { |
|
|
|
AddFile, |
|
|
|
AddIcon, |
|
|
|
ImagePickerContainer, |
|
|
|
ImageUploaded, |
|
|
|
} from "./ImagePicker.styled"; |
|
|
|
import { Tooltip } from "@mui/material"; |
|
|
|
import { Trash } from "../Cards/CreateOfferCard/SecondPart/SecondPartCreateOffer.styled"; |
|
|
|
import { Icon } from "../Icon/Icon"; |
|
|
|
// import { Input } from "@mui/material"; |
|
|
|
|
|
|
|
const ImagePicker = (props) => { |
|
|
|
const fileInputRef = useRef(null); |
|
|
|
const [isOpened, setIsOpened] = useState(false); |
|
|
|
|
|
|
|
const handleChange = () => { |
|
|
|
fileInputRef.current.click(); |
|
|
|
console.log(fileInputRef.current.click); |
|
|
|
}; |
|
|
|
const handleImage = (event) => { |
|
|
|
console.log("fileEvent: ", event.target.files[0]); |
|
|
|
let reader = new FileReader(); |
|
|
|
reader.readAsDataURL(event.target.files[0]); |
|
|
|
reader.onload = () => { |
|
|
|
console.log(reader.result.toString()); |
|
|
|
props.setImage(reader.result); |
|
|
|
}; |
|
|
|
reader.onerror = () => {}; |
|
|
|
}; |
|
|
|
// let timeoutObject = { |
|
|
|
// timeoutFunctionSet: false, |
|
|
|
// timeoutFunction: () => {}, |
|
|
|
// }; |
|
|
|
// const showMessage = (event) => { |
|
|
|
// console.log(event); |
|
|
|
// }; |
|
|
|
// const handleMouseEnter = (event) => { |
|
|
|
// timeoutObject.timeoutFunctionSet = true; |
|
|
|
// timeoutObject.timeoutFunction = setTimeout(() => { |
|
|
|
// showMessage(event); |
|
|
|
// }, 1000); |
|
|
|
// }; |
|
|
|
// const handleMouseMove = (event) => { |
|
|
|
// if (timeoutObject.timeoutFunctionSet) { |
|
|
|
// clearTimeout(timeoutObject.timeoutFunction); |
|
|
|
// timeoutObject.timeoutFunction = setTimeout(() => { |
|
|
|
// showMessage(event); |
|
|
|
// }, 1000); |
|
|
|
// } |
|
|
|
// }; |
|
|
|
// const handleMouseLeave = () => { |
|
|
|
// if (timeoutObject.timeoutFunctionSet) { |
|
|
|
// clearTimeout(timeoutObject.timeoutFunction); |
|
|
|
// timeoutObject.timeoutFunctionSet = false; |
|
|
|
// } |
|
|
|
// }; |
|
|
|
const handleOpen = () => { |
|
|
|
setIsOpened(true); |
|
|
|
if (!props.image) setIsOpened(false); |
|
|
|
}; |
|
|
|
const handleClose = () => { |
|
|
|
setIsOpened(false); |
|
|
|
}; |
|
|
|
const handleDelete = () => { |
|
|
|
props.deleteImage(); |
|
|
|
setIsOpened(false) |
|
|
|
} |
|
|
|
return ( |
|
|
|
<Tooltip |
|
|
|
open={isOpened} |
|
|
|
onOpen={handleOpen} |
|
|
|
onClose={handleClose} |
|
|
|
enterDelay={500} |
|
|
|
enterNextDelay={500} |
|
|
|
arrow |
|
|
|
title={ |
|
|
|
<Icon style={{width: "50px", height: "42px", paddingTop: "10px"}}> |
|
|
|
<Trash onClick={handleDelete} /> |
|
|
|
</Icon> |
|
|
|
} |
|
|
|
d |
|
|
|
> |
|
|
|
<ImagePickerContainer |
|
|
|
className={props.className} |
|
|
|
onClick={!props.image ? handleChange : () => {}} |
|
|
|
hasImage={props.image} |
|
|
|
> |
|
|
|
<AddFile type="file" ref={fileInputRef} onInput={handleImage} /> |
|
|
|
{props.image ? ( |
|
|
|
<ImageUploaded src={props.image} draggable={false}></ImageUploaded> |
|
|
|
) : ( |
|
|
|
<AddIcon /> |
|
|
|
)} |
|
|
|
</ImagePickerContainer> |
|
|
|
</Tooltip> |
|
|
|
); |
|
|
|
}; |
|
|
|
|
|
|
|
ImagePicker.propTypes = { |
|
|
|
children: PropTypes.node, |
|
|
|
className: PropTypes.string, |
|
|
|
setImage: PropTypes.func, |
|
|
|
image: PropTypes.func, |
|
|
|
deleteImage: PropTypes.func |
|
|
|
}; |
|
|
|
|
|
|
|
export default ImagePicker; |