-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
40 lines (32 loc) · 1.08 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const DRAG_AND_DROP_TEXT = 'Drag & drop folder here';
const dragbox = document.getElementById("dragbox");
const dragboxTextEl = document.querySelector('.dragbox-text');
dragboxTextEl.textContent = DRAG_AND_DROP_TEXT;
const dragboxIconPathEl = document.querySelector('.dragbox-icon-path');
const resetDragboxStyling = () => {
dragbox.classList.remove('active');
dragboxTextEl.textContent = DRAG_AND_DROP_TEXT;
dragboxIconPathEl.setAttribute('fill', '#9C8FFF');
}
const handleDragOver = (e) => {
e.stopPropagation();
e.preventDefault();
dragbox.classList.add('active');
dragboxTextEl.textContent = 'Drop it';
dragboxIconPathEl.setAttribute('fill', 'palevioletred');
}
const handleDrop = (e) => {
e.stopPropagation();
e.preventDefault();
const files = e.dataTransfer.files
for (const file of files) {
console.log(file.path);
window.electronAPI.fileDrop(file.path)
}
resetDragboxStyling();
};
dragbox.addEventListener("dragover", handleDragOver);
dragbox.addEventListener('dragleave', () => {
resetDragboxStyling();
});
dragbox.addEventListener("drop", handleDrop);