refac: message drag file input

This commit is contained in:
Timothy J. Baek 2024-01-08 01:12:02 -08:00
parent cc3f84f916
commit df3d95bf2a

View File

@ -119,12 +119,16 @@
onMount(() => {
const dropZone = document.querySelector('body');
dropZone?.addEventListener('dragover', (e) => {
const onDragOver = (e) => {
e.preventDefault();
dragged = true;
});
};
dropZone.addEventListener('drop', async (e) => {
const onDragLeave = () => {
dragged = false;
};
const onDrop = async (e) => {
e.preventDefault();
console.log(e);
@ -158,11 +162,17 @@
}
dragged = false;
});
};
dropZone?.addEventListener('dragleave', () => {
dragged = false;
});
dropZone?.addEventListener('dragover', onDragOver);
dropZone?.addEventListener('drop', onDrop);
dropZone?.addEventListener('dragleave', onDragLeave);
return () => {
dropZone?.removeEventListener('dragover', onDragOver);
dropZone?.removeEventListener('drop', onDrop);
dropZone?.removeEventListener('dragleave', onDragLeave);
};
});
</script>