Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

ui: Add loading spinner for Move Topic popover.

Ryan Rehman16ebf56fd73a
diff --git a/static/js/message_edit.js b/static/js/message_edit.js
index 4e9d97fe936..ba755bdd210 100644
--- a/static/js/message_edit.js
+++ b/static/js/message_edit.js
@@ -8,6 +8,7 @@ const render_topic_edit_form = require("../templates/topic_edit_form.hbs");
const currently_editing_messages = new Map();
let currently_deleting_messages = [];
+let currently_topic_editing_messages = [];
const currently_echoing_messages = new Map();
// These variables are designed to preserve the user's most recent
@@ -178,6 +179,18 @@ exports.show_topic_edit_spinner = function (row) {
$(".topic_edit_cancel").hide();
};
+exports.hide_topic_move_spinner = function () {
+ const spinner = $("#move_topic_modal .topic_move_spinner");
+ loading.destroy_indicator(spinner);
+ $("#move_topic_modal .modal-footer").show();
+};
+
+exports.show_topic_move_spinner = function () {
+ const spinner = $("#move_topic_modal .topic_move_spinner");
+ loading.make_indicator(spinner);
+ $("#move_topic_modal .modal-footer").hide();
+};
+
exports.end_if_focused_on_inline_topic_edit = function () {
const focused_elem = $(".topic_edit_form").find(":focus");
if (focused_elem.length === 1) {
@@ -919,6 +932,23 @@ exports.move_topic_containing_message_to_stream = function (
send_notification_to_new_thread,
send_notification_to_old_thread,
) {
+ function reset_modal_ui() {
+ currently_topic_editing_messages = currently_topic_editing_messages.filter(
+ (id) => id !== message_id,
+ );
+ exports.hide_topic_move_spinner();
+ $("#move_topic_modal").modal("hide");
+ }
+ if (currently_topic_editing_messages.includes(message_id)) {
+ exports.hide_topic_move_spinner();
+ $("#topic_stream_edit_form_error .error-msg").text(
+ i18n.t("A Topic Move already in progress."),
+ );
+ $("#topic_stream_edit_form_error").show();
+ return;
+ }
+ currently_topic_editing_messages.push(message_id);
+
const request = {
stream_id: new_stream_id,
propagate_mode: "change_all",
@@ -934,10 +964,10 @@ exports.move_topic_containing_message_to_stream = function (
success() {
// The main UI will update via receiving the event
// from server_events.js.
- // TODO: This should probably remove a spinner and
- // close the modal.
+ reset_modal_ui();
},
error(xhr) {
+ reset_modal_ui();
ui_report.error(i18n.t("Error moving the topic"), xhr, $("#home-error"), 4000);
},
});
diff --git a/static/js/stream_popover.js b/static/js/stream_popover.js
index 90fd7f0eae5..edf719c0368 100644
--- a/static/js/stream_popover.js
+++ b/static/js/stream_popover.js
@@ -294,7 +294,6 @@ function build_move_topic_to_stream_popover(e, current_stream_id, topic_name) {
});
$("#move_topic_modal").modal("show");
- e.stopPropagation();
}
exports.register_click_handlers = function () {
@@ -610,6 +609,7 @@ exports.register_topic_handlers = function () {
]),
};
+ message_edit.show_topic_move_spinner();
channel.get({
url: "/json/messages",
data,
@@ -631,10 +631,10 @@ exports.register_topic_handlers = function () {
send_notification_to_new_thread,
send_notification_to_old_thread,
);
- $("#move_topic_modal").modal("hide");
}
},
error(xhr) {
+ message_edit.hide_topic_move_spinner();
show_error_msg(xhr.responseJSON.msg);
},
});
diff --git a/static/styles/zulip.scss b/static/styles/zulip.scss
index edeab3411a5..9ec09059998 100644
--- a/static/styles/zulip.scss
+++ b/static/styles/zulip.scss
@@ -2205,6 +2205,7 @@ div.topic_edit_spinner .loading_indicator_spinner {
height: 20px;
}
+.topic_move_spinner,
#do_delete_message_spinner {
margin: 0 auto;
}
diff --git a/static/templates/move_topic_to_stream.hbs b/static/templates/move_topic_to_stream.hbs
index ade355a1ec5..f2f47b0fe9a 100644
--- a/static/templates/move_topic_to_stream.hbs
+++ b/static/templates/move_topic_to_stream.hbs
@@ -37,7 +37,7 @@
</div>
</div>
</form>
- <div class="topic_edit_spinner"></div>
+ <div class="topic_move_spinner"></div>
</div>
<div class="modal-footer">
<button class="button" data-dismiss="modal">{{t "Cancel" }}</button>