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.

message_edit: Handle server errors in inline topic edit.

Sahil Batra271c2a91754e
diff --git a/web/src/message_edit.ts b/web/src/message_edit.ts
index bb53bd5976f..fbc8374b737 100644
--- a/web/src/message_edit.ts
+++ b/web/src/message_edit.ts
@@ -363,6 +363,15 @@ export function show_topic_edit_spinner($row: JQuery): void {
$(".topic_edit_spinner").show();
}
+export function hide_topic_edit_spinner($row: JQuery): void {
+ const $spinner = $row.find(".topic_edit_spinner");
+ loading.destroy_indicator($spinner);
+ $spinner.css({height: ""});
+ $(".topic_edit_save").show();
+ $(".topic_edit_cancel").show();
+ $(".topic_edit_spinner").hide();
+}
+
export function end_if_focused_on_inline_topic_edit(): void {
const $focused_elem = $(".topic_edit").find(":focus");
if ($focused_elem.length === 1) {
@@ -504,8 +513,12 @@ function handle_inline_topic_edit_change(elem: HTMLInputElement, stream_id: numb
// When the topic is mandatory in a realm and the new topic is considered empty,
// we disable the save button and show a tooltip with an error message.
$topic_edit_save_button.prop("disabled", true);
+ $topic_edit_save_button.addClass("topic-required");
return;
}
+
+ $topic_edit_save_button.removeClass("topic-required");
+
// If we reach here, it means the save button was disabled previously
// and the user has started typing in the input field, probably to fix
// the error. So, we re-enable the save button.
@@ -1242,7 +1255,10 @@ export function do_save_inline_topic_edit($row: JQuery, message: Message, new_to
);
return;
}
- loading.destroy_indicator($spinner);
+ hide_topic_edit_spinner($row);
+ const message = channel.xhr_error_message($t({defaultMessage: "Failed"}), xhr);
+ $row.find(".topic_edit_save").prop("disabled", true);
+ $row.find(".topic-edit-save-wrapper").attr("data-tippy-content", message);
},
});
}
diff --git a/web/src/tippyjs.ts b/web/src/tippyjs.ts
index 77c76e150fc..9e6bd7ee00d 100644
--- a/web/src/tippyjs.ts
+++ b/web/src/tippyjs.ts
@@ -913,13 +913,24 @@ export function initialize(): void {
target: ".topic-edit-save-wrapper",
onShow(instance) {
const $elem = $(instance.reference);
- if ($($elem).find(".topic_edit_save").prop("disabled")) {
+ const $save_button = $elem.find(".topic_edit_save");
+ if (!$save_button.prop("disabled")) {
+ return false;
+ }
+
+ if ($save_button.hasClass("topic-required")) {
const error_message =
compose_validate.get_topics_required_error_tooltip_message_html();
instance.setContent(ui_util.parse_html(error_message));
return undefined;
}
- return false;
+
+ const content = $elem.attr("data-tippy-content");
+ if (content === undefined) {
+ return false;
+ }
+ instance.setContent(content);
+ return undefined;
},
appendTo: () => document.body,
onHidden(instance) {