feat: aggiunge drag & drop di cartelle e file zip per lo smistamento

This commit is contained in:
2026-03-05 16:30:03 +01:00
parent 4ab1214171
commit 8edc2673b3
4 changed files with 110 additions and 0 deletions

View File

@@ -1,10 +1,13 @@
const folderBtn = document.getElementById('folderBtn');
const zipBtn = document.getElementById('zipBtn');
const dropZone = document.getElementById('dropZone');
const output = document.getElementById('output');
const destinationInput = document.getElementById('destinationInput');
const browseDestinationBtn = document.getElementById('browseDestinationBtn');
const saveDestinationBtn = document.getElementById('saveDestinationBtn');
const destinationStatus = document.getElementById('destinationStatus');
const defaultDropZoneText = 'Trascina qui una cartella o un file .zip';
let isProcessing = false;
function setLoading(isLoading) {
folderBtn.disabled = isLoading;
@@ -37,6 +40,11 @@ function renderResult(title, result) {
}
async function handleAction(actionName, actionFn) {
if (isProcessing) {
return;
}
isProcessing = true;
setLoading(true);
output.textContent = `${actionName} in corso...`;
@@ -53,12 +61,62 @@ async function handleAction(actionName, actionFn) {
output.textContent = `${actionName} fallito:\n${error.message}`;
} finally {
setLoading(false);
isProcessing = false;
}
}
folderBtn.addEventListener('click', () => handleAction('Process Folder', window.api.selectFolder));
zipBtn.addEventListener('click', () => handleAction('Process ZIP', window.api.selectZip));
function resetDropZoneText() {
dropZone.textContent = defaultDropZoneText;
}
function setDropZoneError(message) {
dropZone.textContent = message;
dropZone.classList.add('error');
setTimeout(() => {
dropZone.classList.remove('error');
resetDropZoneText();
}, 1800);
}
dropZone.addEventListener('dragover', (event) => {
event.preventDefault();
dropZone.classList.add('active');
});
dropZone.addEventListener('dragleave', () => {
dropZone.classList.remove('active');
});
window.addEventListener('dragover', (event) => {
event.preventDefault();
});
window.addEventListener('drop', (event) => {
if (event.target instanceof Node && dropZone.contains(event.target)) {
return;
}
event.preventDefault();
});
dropZone.addEventListener('drop', async (event) => {
event.preventDefault();
dropZone.classList.remove('active');
const droppedFile = event.dataTransfer?.files?.[0];
const droppedPath = droppedFile?.path;
if (!droppedPath) {
setDropZoneError('Elemento non valido. Trascina una cartella o un file .zip');
return;
}
await handleAction('Process Drag & Drop', () => window.api.processDroppedPath(droppedPath));
});
browseDestinationBtn.addEventListener('click', async () => {
try {
setDestinationLoading(true);