Deleted Console logs and adjusted some comments.

This commit is contained in:
ge64qev 2024-05-14 09:13:39 +02:00
parent 36192ba560
commit ce3e98e240
2 changed files with 3 additions and 5 deletions

View file

@ -109,10 +109,7 @@ function setupFileInput(chooser) {
// Listen for event of file being removed and then filter it out of the allFiles array // Listen for event of file being removed and then filter it out of the allFiles array
document.addEventListener("fileRemoved", function (e) { document.addEventListener("fileRemoved", function (e) {
const fileId = e.detail; const fileId = e.detail;
console.log('File to be removed:', fileId); // Log the uniqueId of the file to be removed
console.log('All files before removal:', allFiles); // Log all files before removal
allFiles = allFiles.filter(fileObj => fileObj.uniqueId !== fileId); // Remove the file from the allFiles array using the unique identifier allFiles = allFiles.filter(fileObj => fileObj.uniqueId !== fileId); // Remove the file from the allFiles array using the unique identifier
console.log('All files after removal:', allFiles); // Log all files after removal
// Dispatch a custom event with the allFiles array // Dispatch a custom event with the allFiles array
var filesUpdated = new CustomEvent("filesUpdated", { detail: allFiles }); var filesUpdated = new CustomEvent("filesUpdated", { detail: allFiles });
document.dispatchEvent(filesUpdated); document.dispatchEvent(filesUpdated);

View file

@ -2,6 +2,7 @@ let currentSort = {
field: null, field: null,
descending: false, descending: false,
}; };
//New Array to keep track of unique id
let filesWithUniqueId = []; let filesWithUniqueId = [];
let processedFiles = []; let processedFiles = [];
@ -15,6 +16,7 @@ document.getElementById("fileInput-input").addEventListener("change", function (
filesWithUniqueId = files; filesWithUniqueId = files;
displayFiles(files); displayFiles(files);
}); });
//Get Files Updated Event from FileInput
document.addEventListener("filesUpdated", function (e) { document.addEventListener("filesUpdated", function (e) {
filesWithUniqueId = e.detail; filesWithUniqueId = e.detail;
displayFiles(filesWithUniqueId); displayFiles(filesWithUniqueId);
@ -39,7 +41,7 @@ function displayFiles(files) {
fileNameDiv.className = "filename"; fileNameDiv.className = "filename";
fileNameDiv.textContent = files[i].file.name; fileNameDiv.textContent = files[i].file.name;
// Check for duplicates // Check for duplicates and add a warning if necessary
const duplicateFiles = files.filter(file => file.file.name === files[i].file.name); const duplicateFiles = files.filter(file => file.file.name === files[i].file.name);
if (duplicateFiles.length > 1) { if (duplicateFiles.length > 1) {
const warning = document.createElement("span"); const warning = document.createElement("span");
@ -151,7 +153,6 @@ function updateFiles() {
for (var i = 0; i < liElements.length; i++) { for (var i = 0; i < liElements.length; i++) {
var fileIdFromList = liElements[i].dataset.id; // Get the unique identifier from the list item var fileIdFromList = liElements[i].dataset.id; // Get the unique identifier from the list item
var fileFromFiles;
for (var j = 0; j < filesWithUniqueId.length; j++) { for (var j = 0; j < filesWithUniqueId.length; j++) {
var fileObj = filesWithUniqueId[j]; var fileObj = filesWithUniqueId[j];
if (fileObj.uniqueId === fileIdFromList) { if (fileObj.uniqueId === fileIdFromList) {