Remove window.fileList in profit of a counter

This commit is contained in:
Booteille 2024-11-14 20:42:54 +01:00
parent 043ffb42ca
commit 1658e35832
No known key found for this signature in database
GPG Key ID: 0AB6C6CA01272646
1 changed files with 24 additions and 28 deletions

View File

@ -14,11 +14,12 @@ window.cancelled = [];
window.zipSize = 0; window.zipSize = 0;
// Init the list of files (used by LDAP invitation feature) // Init the list of files (used by LDAP invitation feature)
window.filesURLs = []; window.filesURLs = [];
let filesCounter = 0;
let archiveEntries; let archiveEntries;
// Copy a link to clipboard // Copy a link to clipboard
function copyToClipboard(txt) { const copyToClipboard = (txt) => {
const textArea = document.createElement("textarea"); const textArea = document.createElement("textarea");
textArea.className = "textarea-hidden"; textArea.className = "textarea-hidden";
textArea.value = txt; textArea.value = txt;
@ -36,10 +37,10 @@ function copyToClipboard(txt) {
} }
textArea.remove(); textArea.remove();
} };
// Copy all links to clipboard // Copy all links to clipboard
function copyAllToClipboard(event) { const copyAllToClipboard = (event) => {
event.preventDefault(); event.preventDefault();
let text = []; let text = [];
const inputs = document.querySelectorAll(".link-input"); const inputs = document.querySelectorAll(".link-input");
@ -54,10 +55,10 @@ function copyAllToClipboard(event) {
} catch (err) { } catch (err) {
alert(i18n.hits); alert(i18n.hits);
} }
} };
// Add item to localStorage // Add item to localStorage
function addItem( const addItem = (
name, name,
url, url,
size, size,
@ -66,7 +67,7 @@ function addItem(
delay, delay,
short, short,
token token
) { ) => {
let files = localStorage.getItem(`${window.prefix}files`); let files = localStorage.getItem(`${window.prefix}files`);
files = JSON.parse(files) || []; files = JSON.parse(files) || [];
@ -81,27 +82,28 @@ function addItem(
token, token,
}); });
localStorage.setItem(`${window.prefix}files`, JSON.stringify(files)); localStorage.setItem(`${window.prefix}files`, JSON.stringify(files));
} };
// Remove a file block // Remove a file block
function destroyBlock(clientKey) { const destroyBlock = (clientKey) => {
filesCounter--;
document.getElementById(`list-group-item-${clientKey}`).remove(); document.getElementById(`list-group-item-${clientKey}`).remove();
if (document.querySelectorAll(".link-input").length === 0) { if (document.querySelectorAll(".link-input").length === 0) {
document.getElementById("misc").innerHTML = ""; document.getElementById("misc").innerHTML = "";
if ( if (
document.querySelectorAll("#results li").length === 0 && document.querySelectorAll("#results li").length === 0 &&
window.fileList === null filesCounter === 0
) { ) {
document.getElementById("results").style.display = "none"; document.getElementById("results").style.display = "none";
} }
} else { } else {
updateMailLink(); updateMailLink();
} }
} };
// When clicking on del at first view checkbox // When clicking on del at first view checkbox
function firstViewClicking() { const firstViewClicking = () => {
document document
.getElementById("first-view") .getElementById("first-view")
.setAttribute( .setAttribute(
@ -111,10 +113,10 @@ function firstViewClicking() {
? null ? null
: "data-checked" : "data-checked"
); );
} };
// When clicking on zip checkbox // When clicking on zip checkbox
function zipClicking() { const zipClicking = () => {
if ( if (
document.getElementById("zip-files").getAttribute("data-checked") === document.getElementById("zip-files").getAttribute("data-checked") ===
"data-checked" "data-checked"
@ -134,7 +136,7 @@ function zipClicking() {
document.getElementById("zipname-input").classList.remove("hide"); document.getElementById("zipname-input").classList.remove("hide");
document.getElementById("zip-size").innerText = filesize(window.zipSize); document.getElementById("zip-size").innerText = filesize(window.zipSize);
} }
} };
// Get the zip file name // Get the zip file name
const getZipname = () => { const getZipname = () => {
@ -191,8 +193,6 @@ const uploadZip = (e) => {
"teal accent-3" "teal accent-3"
); );
window.fileList = window.fileList || [zipFile];
startUpload( startUpload(
[zipFile], [zipFile],
delay.value, delay.value,
@ -357,6 +357,10 @@ const startUpload = (
.andThen((jobs) => .andThen((jobs) =>
ResultAsync.combine( ResultAsync.combine(
jobs.map((job) => { jobs.map((job) => {
filesCounter++;
document.getElementById("results").style.display = "block";
clientKey = job.lufiFile.keys.client; clientKey = job.lufiFile.keys.client;
createUploadBox(job); createUploadBox(job);
@ -437,16 +441,6 @@ const handleFiles = (files = []) => {
document.getElementById("first-view").getAttribute("data-checked") === document.getElementById("first-view").getAttribute("data-checked") ===
"data-checked"; "data-checked";
const password = document.getElementById("file_pwd").value; const password = document.getElementById("file_pwd").value;
const resultsElement = document.getElementById("results");
if (window.fileList === undefined || window.fileList === null) {
window.fileList = filesArray; // Convert FileList to an array
if (resultsElement) {
resultsElement.style.display = "block";
}
} else {
window.fileList = window.fileList.concat(filesArray); // Concatenate new files
}
filesArray.forEach((file) => { filesArray.forEach((file) => {
Materialize.toast( Materialize.toast(
@ -455,7 +449,6 @@ const handleFiles = (files = []) => {
"teal accent-3" "teal accent-3"
); );
}); });
window.nbFiles = window.fileList.length;
document.body.style.cursor = "auto"; document.body.style.cursor = "auto";
@ -627,7 +620,10 @@ const uploadBoxComplete = (lufiFile) => {
// Select input text on click // Select input text on click
document.querySelectorAll("input[type='text']").forEach((input) => { document.querySelectorAll("input[type='text']").forEach((input) => {
input.addEventListener("click", function () { input.addEventListener("click", () => {
this.select();
});
input.addEventListener("keydown", () => {
this.select(); this.select();
}); });
}); });