From c34df79b7c0b98172af73c87def5e2d7d033fdd7 Mon Sep 17 00:00:00 2001 From: Aevann Date: Thu, 14 Nov 2024 01:23:49 +0200 Subject: [PATCH] [post editing] hide upload progress when error --- files/assets/js/core.js | 16 ++++++++-------- files/assets/js/post.js | 7 ------- files/templates/post.html | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/files/assets/js/core.js b/files/assets/js/core.js index d29da33da..b6d945764 100644 --- a/files/assets/js/core.js +++ b/files/assets/js/core.js @@ -312,7 +312,7 @@ function reload() { location.reload(); } -function setupFormXhr(form, extraActionsOnSuccess) { +function sendFormXHR(form, extraActionsOnSuccess, upload_prog) { if (typeof close_inline_emoji_modal === "function") { close_inline_emoji_modal(); } @@ -323,6 +323,9 @@ function setupFormXhr(form, extraActionsOnSuccess) { const xhr = new XMLHttpRequest(); + upload_prog = document.getElementById(upload_prog); + xhr.upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)}; + formData = new FormData(form); formData.append("formkey", formkey()); @@ -332,6 +335,8 @@ function setupFormXhr(form, extraActionsOnSuccess) { xhr.setRequestHeader('xhr', 'xhr'); xhr.onload = function() { + upload_prog.classList.add("d-none") + const success = xhr.status >= 200 && xhr.status < 300; if (!(extraActionsOnSuccess == reload && success)) { @@ -354,11 +359,6 @@ function setupFormXhr(form, extraActionsOnSuccess) { form.classList.remove('is-submitting'); }; - return xhr -} - -function sendFormXHR(form, extraActionsOnSuccess) { - const xhr = setupFormXhr(form, extraActionsOnSuccess); xhr.send(formData); } @@ -373,8 +373,8 @@ function sendFormXHRSwitch(form) { ) } -function sendFormXHRReload(form) { - sendFormXHR(form, reload) +function sendFormXHRReload(form, upload_prog) { + sendFormXHR(form, reload, upload_prog) } let sortAscending = {}; diff --git a/files/assets/js/post.js b/files/assets/js/post.js index e7afa14ed..dde537eed 100644 --- a/files/assets/js/post.js +++ b/files/assets/js/post.js @@ -46,11 +46,4 @@ if (fake_textarea) { fake_textarea.addEventListener('click', () => { location.href = fake_textarea.dataset.href; }); -} - -function edit_post(form) { - const xhr = setupFormXhr(form, reload); - const upload_prog = document.getElementById('upload-prog-edit-post'); - xhr.upload.onprogress = (e) => {handleUploadProgress(e, upload_prog)}; - xhr.send(formData); } \ No newline at end of file diff --git a/files/templates/post.html b/files/templates/post.html index e7948fc8f..4b3d8739f 100644 --- a/files/templates/post.html +++ b/files/templates/post.html @@ -215,7 +215,7 @@ {% if v and v.can_edit(p) %}