compose banner: Add specific functions to clear warnings and errors.

Instead of removing all compose banners, we now remove only warnings
and errors -- this makes no difference right now, but this change
will allow us to add other compose banners that are cleared at
different times.
This commit is contained in:
evykassirer 2022-12-09 16:20:07 -08:00 committed by Tim Abbott
parent 2e825f637d
commit 1b0a14bf40
5 changed files with 20 additions and 4 deletions

View File

@ -9,4 +9,6 @@ exports.mock_banners = () => {
for (const classname of Object.values(compose_banner.CLASSNAMES)) { for (const classname of Object.values(compose_banner.CLASSNAMES)) {
$(`#compose_banners .${classname}`).remove = () => {}; $(`#compose_banners .${classname}`).remove = () => {};
} }
$("#compose_banners .warning").remove = () => {};
$("#compose_banners .error").remove = () => {};
}; };

View File

@ -196,7 +196,8 @@ export function clear_compose_box() {
$("#compose-textarea").removeData("draft-id"); $("#compose-textarea").removeData("draft-id");
compose_ui.autosize_textarea($("#compose-textarea")); compose_ui.autosize_textarea($("#compose-textarea"));
$("#compose-send-status").hide(0); $("#compose-send-status").hide(0);
$("#compose_banners").empty(); compose_banner.clear_errors();
compose_banner.clear_warnings();
compose_ui.hide_compose_spinner(); compose_ui.hide_compose_spinner();
} }

View File

@ -7,6 +7,7 @@ import * as fenced_code from "../shared/js/fenced_code";
import * as channel from "./channel"; import * as channel from "./channel";
import * as common from "./common"; import * as common from "./common";
import * as compose from "./compose"; import * as compose from "./compose";
import * as compose_banner from "./compose_banner";
import * as compose_fade from "./compose_fade"; import * as compose_fade from "./compose_fade";
import * as compose_pm_pill from "./compose_pm_pill"; import * as compose_pm_pill from "./compose_pm_pill";
import * as compose_state from "./compose_state"; import * as compose_state from "./compose_state";
@ -92,7 +93,8 @@ function show_compose_box(msg_type, opts) {
$("#private_message_toggle").addClass("active"); $("#private_message_toggle").addClass("active");
} }
$("#compose-send-status").removeClass(common.status_classes).hide(); $("#compose-send-status").removeClass(common.status_classes).hide();
$("#compose_banners").empty(); compose_banner.clear_errors();
compose_banner.clear_warnings();
$("#compose").css({visibility: "visible"}); $("#compose").css({visibility: "visible"});
// When changing this, edit the 42px in _maybe_autoscroll // When changing this, edit the 42px in _maybe_autoscroll
$(".new_message_textarea").css("min-height", "3em"); $(".new_message_textarea").css("min-height", "3em");
@ -119,7 +121,8 @@ function clear_box() {
$("#compose-textarea").removeData("draft-id"); $("#compose-textarea").removeData("draft-id");
compose_ui.autosize_textarea($("#compose-textarea")); compose_ui.autosize_textarea($("#compose-textarea"));
$("#compose-send-status").hide(0); $("#compose-send-status").hide(0);
$("#compose_banners").empty(); compose_banner.clear_errors();
compose_banner.clear_warnings();
} }
export function autosize_message_content() { export function autosize_message_content() {

View File

@ -39,6 +39,14 @@ function hide_compose_spinner(): void {
$("#compose-send-button").removeClass("disable-btn"); $("#compose-send-button").removeClass("disable-btn");
} }
export function clear_errors(): void {
$(`#compose_banners .${ERROR}`).remove();
}
export function clear_warnings(): void {
$(`#compose_banners .${WARNING}`).remove();
}
export function show_error_message(message: string, classname: string, $bad_input?: JQuery): void { export function show_error_message(message: string, classname: string, $bad_input?: JQuery): void {
$(`#compose_banners .${classname}`).remove(); $(`#compose_banners .${classname}`).remove();

View File

@ -5,6 +5,7 @@ import * as browser_history from "./browser_history";
import * as common from "./common"; import * as common from "./common";
import * as compose from "./compose"; import * as compose from "./compose";
import * as compose_actions from "./compose_actions"; import * as compose_actions from "./compose_actions";
import * as compose_banner from "./compose_banner";
import * as compose_state from "./compose_state"; import * as compose_state from "./compose_state";
import * as condense from "./condense"; import * as condense from "./condense";
import * as copy_and_paste from "./copy_and_paste"; import * as copy_and_paste from "./copy_and_paste";
@ -311,7 +312,8 @@ export function process_escape_key(e) {
// Clear open compose banners, if present. // Clear open compose banners, if present.
if ($(".compose_banner").length) { if ($(".compose_banner").length) {
$("#compose_banners").empty(); compose_banner.clear_errors();
compose_banner.clear_warnings();
return true; return true;
} }