Clean up.
This commit is contained in:
parent
fc760ed471
commit
b3ce370b1e
1 changed files with 20 additions and 10 deletions
|
@ -14,17 +14,27 @@ type Props = React.PropsWithChildren<{
|
|||
|
||||
export default function FullScreenDropZone({ children, showModal, closeModal }: Props) {
|
||||
const closeTimer = useRef<number>();
|
||||
|
||||
const clearTimer = () => {
|
||||
if (closeTimer.current) {
|
||||
clearTimeout(closeTimer.current);
|
||||
}
|
||||
}
|
||||
|
||||
const onDragOver = (e) => {
|
||||
e.preventDefault();
|
||||
clearTimer();
|
||||
showModal();
|
||||
}
|
||||
|
||||
const onDragLeave = (e) => {
|
||||
e.preventDefault();
|
||||
clearTimer();
|
||||
closeTimer.current = setTimeout(closeModal, 1000);
|
||||
}
|
||||
|
||||
return (
|
||||
<DropDiv onDragOver={(ev) => {
|
||||
// ev.preventDefault();
|
||||
if (closeTimer.current) {
|
||||
clearTimeout(closeTimer.current);
|
||||
}
|
||||
showModal();
|
||||
}} onDragLeave={(ev) => {
|
||||
// ev.preventDefault();
|
||||
closeTimer.current = setTimeout(closeModal, 300);
|
||||
}}>
|
||||
<DropDiv onDragOver={onDragOver} onDragLeave={onDragLeave}>
|
||||
{children}
|
||||
</DropDiv>
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue