Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
popup_banner: Fix retry attempt rolled back to 1 on button click.
Aman Agrawale5f4ba92f104
diff --git a/web/src/popup_banners.ts b/web/src/popup_banners.tsindex be929e32419..645cc87d231 100644--- a/web/src/popup_banners.ts+++ b/web/src/popup_banners.ts@@ -131,12 +131,38 @@ export function close_found_missing_unreads_banner(): void {fade_out_popup_banner($banner);}+function retry_connection_click_handler(e: JQuery.ClickEvent, on_retry_callback: () => void): void {+ e.preventDefault();+ e.stopPropagation();++ const $banner = $(e.currentTarget).closest(".banner");+ $banner+ .find(".banner-label")+ .text($t({defaultMessage: "Unable to connect to Zulip. Retrying now…"}));++ const $button = $(e.currentTarget).closest(".retry-connection");++ // If the loading indicator is already being shown, this logic+ // allows us to visually indicate that the retry sequence was+ // executed again by showing the loading indicator on click.+ $button.removeClass("button-hide-loading-indicator-on-hover");+ $button.one("mouseleave", () => {+ $button.addClass("button-hide-loading-indicator-on-hover");+ });++ buttons.show_button_loading_indicator($button);+ on_retry_callback();+}+export function open_connection_error_popup_banner(opts: {caller: "server_events" | "message_fetch";retry_delay_secs: number;on_retry_callback: () => void;}): void {opts.retry_delay_secs = Math.round(opts.retry_delay_secs);+ const retry_connection_attached_click_handler = (e: JQuery.ClickEvent): void => {+ retry_connection_click_handler(e, opts.on_retry_callback);+ };// If the banner is already open, don't open it again, and instead remove// the loading indicator on the retry button, if it was being shown.let $banner = $("#popup_banners_wrapper").find(".connection-error-banner");@@ -157,6 +183,10 @@ export function open_connection_error_popup_banner(opts: {buttons.hide_button_loading_indicator($retry_connection_button);}, 1000);}+ // Update the click handler to the new on_retry_callback.+ // Remove any click events on the button.+ $retry_connection_button.off("click");+ $retry_connection_button.on("click", retry_connection_attached_click_handler);return;}@@ -174,28 +204,11 @@ export function open_connection_error_popup_banner(opts: {update_connection_error_banner($banner, opts.retry_delay_secs);- $("#popup_banners_wrapper").on("click", ".retry-connection", function (this: HTMLElement, e) {- e.preventDefault();- e.stopPropagation();-- const $banner = $(this).closest(".banner");- $banner- .find(".banner-label")- .text($t({defaultMessage: "Unable to connect to Zulip. Retrying now…"}));-- const $button = $(this);-- // If the loading indicator is already being shown, this logic- // allows us to visually indicate that the retry sequence was- // executed again by showing the loading indicator on click.- $button.removeClass("button-hide-loading-indicator-on-hover");- $button.one("mouseleave", () => {- $button.addClass("button-hide-loading-indicator-on-hover");- });-- buttons.show_button_loading_indicator($button);- opts.on_retry_callback();- });+ $("#popup_banners_wrapper").on(+ "click",+ ".retry-connection",+ retry_connection_attached_click_handler,+ );}export function close_connection_error_popup_banner(