Change the SortFiles Method, so it works with the filesWithUniqueID Array

This commit is contained in:
ge64qev 2024-05-14 08:49:27 +02:00
parent 0e262dc2bd
commit 36192ba560

View file

@ -132,15 +132,15 @@ document.getElementById("sortByDateBtn").addEventListener("click", function () {
}); });
function sortFiles(comparator) { function sortFiles(comparator) {
// Convert FileList to array and sort // Sort the filesWithUniqueId array
const sortedFilesArray = Array.from(document.getElementById("fileInput-input").files).sort(comparator); const sortedFilesArray = filesWithUniqueId.sort((a, b) => comparator(a.file, b.file));
// Refresh displayed list // Refresh displayed list
displayFiles(sortedFilesArray); displayFiles(sortedFilesArray);
// Update the files property // Update the files property
const dataTransfer = new DataTransfer(); const dataTransfer = new DataTransfer();
sortedFilesArray.forEach((file) => dataTransfer.items.add(file)); sortedFilesArray.forEach((fileObj) => dataTransfer.items.add(fileObj.file));
document.getElementById("fileInput-input").files = dataTransfer.files; document.getElementById("fileInput-input").files = dataTransfer.files;
} }