Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
settings: Update save button style when "Saved" is shown.
Sayam Samalb115368a812b
diff --git a/web/src/buttons.ts b/web/src/buttons.tsindex 3067b611cb1..769185d12c1 100644--- a/web/src/buttons.ts+++ b/web/src/buttons.ts@@ -1,6 +1,7 @@import $ from "jquery";import * as loading from "./loading.ts";+import {COMPONENT_INTENT_VALUES} from "./types.ts";import type {ComponentIntent} from "./types.ts";export const ACTION_BUTTON_ATTENTION_VALUES = ["primary", "quiet", "borderless"] as const;@@ -50,3 +51,32 @@ export function hide_button_loading_indicator($button: JQuery): void {$button.find(".zulip-icon").css("visibility", "visible");$button.find(".action-button-label").css("visibility", "visible");}++export function modify_action_button_style(+ $button: JQuery,+ opts: {+ attention?: ActionButtonAttention;+ intent?: ComponentIntent;+ },+): void {+ if (opts.attention === undefined && opts.intent === undefined) {+ // If neither attention nor intent is provided, do nothing.+ return;+ }+ const action_button_attention_pattern = ACTION_BUTTON_ATTENTION_VALUES.join("|");+ const component_intent_pattern = COMPONENT_INTENT_VALUES.join("|");+ const action_button_style_regex = new RegExp(+ `action-button-(${action_button_attention_pattern})-(${component_intent_pattern})`,+ );+ const action_button_style_regex_match = $button.attr("class")?.match(action_button_style_regex);+ if (!action_button_style_regex_match) {+ // If the button doesn't have the expected class, do nothing.+ return;+ }+ const [action_button_style_class, old_attention, old_intent] = action_button_style_regex_match;+ // Replace the old attention and intent values with the new ones, if provided.+ $button.removeClass(action_button_style_class);+ $button.addClass(+ `action-button-${opts.attention ?? old_attention}-${opts.intent ?? old_intent}`,+ );+}diff --git a/web/src/settings_components.ts b/web/src/settings_components.tsindex 5fe96671614..6b3f6fe374d 100644--- a/web/src/settings_components.ts+++ b/web/src/settings_components.ts@@ -557,19 +557,17 @@ export function change_save_button_state($element: JQuery, state: string): voidreturn;}- let button_text;+ let button_text = $t({defaultMessage: "Save changes"});let data_status;let is_show;switch (state) {case "unsaved":- button_text = $t({defaultMessage: "Save changes"});data_status = "unsaved";is_show = true;$element.find(".discard-button").show();break;case "saved":- button_text = $t({defaultMessage: "Save changes"});data_status = "";is_show = false;break;@@ -584,7 +582,6 @@ export function change_save_button_state($element: JQuery, state: string): voidbuttons.show_button_loading_indicator($save_button);break;case "failed":- button_text = $t({defaultMessage: "Save changes"});data_status = "failed";is_show = true;break;@@ -595,9 +592,23 @@ export function change_save_button_state($element: JQuery, state: string): voidbreak;}- if (button_text !== undefined) {+ requestAnimationFrame(() => {+ // We need to use requestAnimationFrame to ensure that the+ // button text and style are updated in the same frame.$textEl.text(button_text);- }+ if (state === "succeeded") {+ buttons.modify_action_button_style($save_button, {+ attention: "borderless",+ intent: "success",+ });+ } else {+ buttons.modify_action_button_style($save_button, {+ attention: "primary",+ intent: "brand",+ });+ }+ });+assert(data_status !== undefined);$save_button.attr("data-status", data_status);if (state === "unsaved") {diff --git a/web/styles/app_components.css b/web/styles/app_components.cssindex f5653439a1d..7ad4b134975 100644--- a/web/styles/app_components.css+++ b/web/styles/app_components.css@@ -885,6 +885,10 @@ input.settings_text_input {&.hide {display: none;}++ .save-button[data-status="saved"] {+ pointer-events: none;+ }}.stream-privacy-type-icon {diff --git a/web/tests/settings_org.test.cjs b/web/tests/settings_org.test.cjsindex 128c775106e..0099979deb2 100644--- a/web/tests/settings_org.test.cjs+++ b/web/tests/settings_org.test.cjs@@ -19,10 +19,13 @@ mock_esm("../src/loading", {mock_esm("../src/buttons", {show_button_loading_indicator: noop,hide_button_loading_indicator: noop,+ modify_action_button_style: noop,});mock_esm("../src/scroll_util", {scroll_element_into_container: noop});set_global("document", "document-stub");+set_global("requestAnimationFrame", (func) => func());+const settings_account = zrequire("settings_account");const settings_components = zrequire("settings_components");const settings_config = zrequire("settings_config");