From 6d33e73b5fc75994710f8401e448b6f9876845ea Mon Sep 17 00:00:00 2001 From: Shubham Dhama Date: Sat, 14 Apr 2018 15:09:14 +0530 Subject: [PATCH] upload: Remove progress bar only when upload is finished. Previous logic was little buggy, as many time there can be considerable difference between uploadFinished and progressUpdated as progressUpdated can finish much earlier(on a slow connection) and the "uploaded file" markdown text is inserted with some delay. It is also a preliminary commit for making each progress bar independent as currently progressUpdated may close upload_bar even after only one file out of many files is uploaded. --- static/js/upload.js | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/static/js/upload.js b/static/js/upload.js index 4d9ea5e4bb..a7cc55bd61 100644 --- a/static/js/upload.js +++ b/static/js/upload.js @@ -24,7 +24,6 @@ exports.options = function (config) { var send_status_close; var error_msg; var upload_bar; - var should_hide_upload_status; var file_input; switch (config.mode) { @@ -50,41 +49,29 @@ exports.options = function (config) { throw Error("Invalid upload mode!"); } - var maybe_hide_upload_status = function () { - // The first time `maybe_hide_upload_status`, it will not hide the - // status; the second time it will. This guarantees that whether - // `progressUpdated` or `uploadFinished` is called first, the status - // is hidden only after the animation is finished. - if (should_hide_upload_status) { - setTimeout(function () { - send_button.prop("disabled", false); - send_status.removeClass("alert-info").hide(); - $("#" + upload_bar).parent().remove(); - }, 500); - } else { - should_hide_upload_status = true; - } + var hide_upload_status = function () { + setTimeout(function () { + send_button.prop("disabled", false); + send_status.removeClass("alert-info").hide(); + $("#" + upload_bar).parent().remove(); + }, 500); }; var drop = function () { send_button.attr("disabled", ""); send_status.addClass("alert-info").show(); send_status_close.one('click', function () { - maybe_hide_upload_status(); + hide_upload_status(); compose.abort_xhr(); }); error_msg.html($("

").text(i18n.t("Uploading…"))); send_status.append('

' + '
' + '
'); - should_hide_upload_status = false; }; var progressUpdated = function (i, file, progress) { $("#" + upload_bar).width(progress + "%"); - if (progress === 100) { - maybe_hide_upload_status(); - } }; var uploadError = function (error_code, server_response, file) { @@ -146,7 +133,7 @@ exports.options = function (config) { } compose_ui.autosize_textarea(); - maybe_hide_upload_status(); + hide_upload_status(); // In order to upload the same file twice in a row, we need to clear out // the file input element, so that the next time we use the file dialog,