settings: Extract common logic for show_spinner.

Consolidate the repeated logic for showing spinners into a shared
`show_spinner` function in `loading.ts`. This eliminates code
duplication between `show_button_spinner` and `show_dialog_spinner`,
streamlining spinner initialization and button disabling.

Fixes part of #26691.
This commit is contained in:
Maneesh Shukla 2024-10-17 00:25:47 +05:30 committed by Tim Abbott
parent 9ad85445f8
commit 666e7bf433
3 changed files with 17 additions and 17 deletions

View File

@ -102,17 +102,8 @@ export function show_dialog_spinner(): void {
$(`${dialog_widget_selector} .modal__btn`).prop("disabled", true);
const $spinner = $(`${dialog_widget_selector} .modal__spinner`);
const dialog_submit_button_span_width = $(".dialog_submit_button span").width();
const dialog_submit_button_span_height = $(".dialog_submit_button span").height();
// Hide the submit button after computing its height, since submit
// buttons with long text might affect the size of the button.
$(".dialog_submit_button span").hide();
loading.make_indicator($spinner, {
width: dialog_submit_button_span_width,
height: dialog_submit_button_span_height,
});
loading.show_spinner($(".dialog_submit_button"), $spinner);
}
// Supports a callback to be called once the modal finishes closing.

View File

@ -91,3 +91,18 @@ export function show_button_spinner($elt: JQuery, using_dark_theme: boolean): vo
}
$elt.css("display", "inline-block");
}
export function show_spinner($button_element: JQuery, $spinner: JQuery): void {
const span_width = $button_element.find(".submit-button-text").width();
const span_height = $button_element.find(".submit-button-text").height();
// Hide the submit button after computing its height, since submit
// buttons with long text might affect the size of the button.
$button_element.find(".submit-button-text").hide();
// Create the loading indicator
make_indicator($spinner, {
width: span_width,
height: span_height,
});
}

View File

@ -88,14 +88,8 @@ const EMBEDDED_BOT_TYPE = "4";
export function show_button_spinner($button: JQuery): void {
const $spinner = $button.find(".modal__spinner");
const dialog_submit_button_span_width = $button.find("span").width();
const dialog_submit_button_span_height = $button.find("span").height();
$button.prop("disabled", true);
$button.find("span").hide();
loading.make_indicator($spinner, {
width: dialog_submit_button_span_width,
height: dialog_submit_button_span_height,
});
loading.show_spinner($button, $spinner);
}
export function hide_button_spinner($button: JQuery): void {