From c124d3cf049ef57ea9ff6241046e460fc8f13b78 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 10 Oct 2022 20:51:01 +0200 Subject: [PATCH] show upload to user --- src/public/js/main.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/public/js/main.js b/src/public/js/main.js index 825e39e..7a3fefc 100644 --- a/src/public/js/main.js +++ b/src/public/js/main.js @@ -11,7 +11,7 @@ const main = () => { const input = document.getElementById("upload"); input.onchange = () => { - fetchFile(input.files); + fetchFile(input.files, input); }; }; @@ -19,9 +19,9 @@ const main = () => { * Check if they're is only one file and send it * @param list List of files */ -const fetchFile = (list) => { +const fetchFile = (list, element = undefined) => { if (list.length == 1) { - send(list[0]); + send(list[0], element); } }; @@ -29,7 +29,16 @@ const fetchFile = (list) => { * Send a file to the server * @param file File to send */ -const send = (file) => { +const send = (file, element) => { + // Show the user a file is uploading + if (element) { + let parent = element.parentElement; + parent.textContent = ""; + let newText = document.createElement("h3"); + newText.textContent = "Téléversement..."; + parent.appendChild(newText); + } + // TODO: Encrypt the file before sending it const data = new FormData(); data.append("file", file);