mirror of https://github.com/zulip/zulip.git
compose banner: Consolidate two functions that clear success banners.
Previously notifications.clear_compose_notifications was used accross the codebase. Since introducing the new compose_banner.clear_message_sent_banners function, the two functions are similar enough that we can just use clear_message_sent_banners everywhere. This commit also moves scroll_to_message_banner_message_id to compose_banner.
This commit is contained in:
parent
ea9c4682a8
commit
5f59ea0036
|
@ -43,7 +43,7 @@ const transmit = mock_esm("../../static/js/transmit");
|
|||
const upload = mock_esm("../../static/js/upload");
|
||||
|
||||
const compose_ui = zrequire("compose_ui");
|
||||
const notifications = zrequire("notifications");
|
||||
const compose_banner = zrequire("compose_banner");
|
||||
const compose_closed_ui = zrequire("compose_closed_ui");
|
||||
const compose_state = zrequire("compose_state");
|
||||
const compose = zrequire("compose");
|
||||
|
@ -293,7 +293,7 @@ test_ui("send_message", ({override, override_rewire, mock_template}) => {
|
|||
|
||||
test_ui("enter_with_preview_open", ({override, override_rewire}) => {
|
||||
mock_banners();
|
||||
override_rewire(notifications, "clear_compose_notifications", () => {});
|
||||
override_rewire(compose_banner, "clear_message_sent_banners", () => {});
|
||||
override(reminder, "is_deferred_delivery", () => false);
|
||||
override(document, "to_$", () => $("document-stub"));
|
||||
let show_button_spinner_called = false;
|
||||
|
@ -342,7 +342,7 @@ test_ui("enter_with_preview_open", ({override, override_rewire}) => {
|
|||
|
||||
test_ui("finish", ({override, override_rewire, mock_template}) => {
|
||||
mock_banners();
|
||||
override_rewire(notifications, "clear_compose_notifications", () => {});
|
||||
override_rewire(compose_banner, "clear_message_sent_banners", () => {});
|
||||
override(reminder, "is_deferred_delivery", () => false);
|
||||
override(document, "to_$", () => $("document-stub"));
|
||||
let show_button_spinner_called = false;
|
||||
|
|
|
@ -13,6 +13,7 @@ mock_esm("../../static/js/resize", {
|
|||
const all_messages_data = mock_esm("../../static/js/all_messages_data");
|
||||
const channel = mock_esm("../../static/js/channel");
|
||||
const compose_actions = mock_esm("../../static/js/compose_actions");
|
||||
const compose_banner = mock_esm("../../static/js/compose_banner");
|
||||
const compose_closed_ui = mock_esm("../../static/js/compose_closed_ui");
|
||||
const hashchange = mock_esm("../../static/js/hashchange");
|
||||
const message_fetch = mock_esm("../../static/js/message_fetch");
|
||||
|
@ -71,13 +72,13 @@ function test_helper() {
|
|||
};
|
||||
}
|
||||
|
||||
stub(compose_banner, "clear_message_sent_banners");
|
||||
stub(compose_actions, "on_narrow");
|
||||
stub(compose_closed_ui, "update_reply_recipient_label");
|
||||
stub(hashchange, "save_narrow");
|
||||
stub(message_scroll, "hide_indicators");
|
||||
stub(message_scroll, "show_loading_older");
|
||||
stub(message_scroll, "hide_top_of_narrow_notices");
|
||||
stub(notifications, "clear_compose_notifications");
|
||||
stub(notifications, "redraw_title");
|
||||
stub(search, "update_button_visibility");
|
||||
stub(stream_list, "handle_narrow_activated");
|
||||
|
@ -186,7 +187,7 @@ run_test("basics", () => {
|
|||
helper.assert_events([
|
||||
[message_scroll, "hide_top_of_narrow_notices"],
|
||||
[message_scroll, "hide_indicators"],
|
||||
[notifications, "clear_compose_notifications"],
|
||||
[compose_banner, "clear_message_sent_banners"],
|
||||
[notifications, "redraw_title"],
|
||||
[unread_ops, "process_visible"],
|
||||
[hashchange, "save_narrow"],
|
||||
|
|
|
@ -19,7 +19,6 @@ import * as loading from "./loading";
|
|||
import * as markdown from "./markdown";
|
||||
import * as message_edit from "./message_edit";
|
||||
import * as narrow from "./narrow";
|
||||
import * as notifications from "./notifications";
|
||||
import {page_params} from "./page_params";
|
||||
import * as people from "./people";
|
||||
import * as reminder from "./reminder";
|
||||
|
@ -308,7 +307,7 @@ export function finish() {
|
|||
clear_preview_area();
|
||||
clear_invites();
|
||||
clear_private_stream_alert();
|
||||
notifications.clear_compose_notifications();
|
||||
compose_banner.clear_message_sent_banners();
|
||||
|
||||
const message_content = compose_state.message_content();
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ import {$t} from "./i18n";
|
|||
import * as message_lists from "./message_lists";
|
||||
import * as message_viewport from "./message_viewport";
|
||||
import * as narrow_state from "./narrow_state";
|
||||
import * as notifications from "./notifications";
|
||||
import {page_params} from "./page_params";
|
||||
import * as people from "./people";
|
||||
import * as recent_topics_ui from "./recent_topics_ui";
|
||||
|
@ -292,7 +291,7 @@ export function start(msg_type, opts) {
|
|||
if (reload_state.is_in_progress()) {
|
||||
return;
|
||||
}
|
||||
notifications.clear_compose_notifications();
|
||||
compose_banner.clear_message_sent_banners();
|
||||
expand_compose_box();
|
||||
|
||||
opts = fill_in_opts_from_current_narrowed_view(msg_type, opts);
|
||||
|
@ -384,7 +383,7 @@ export function cancel() {
|
|||
hide_box();
|
||||
$("#compose_close").hide();
|
||||
clear_box();
|
||||
notifications.clear_compose_notifications();
|
||||
compose_banner.clear_message_sent_banners();
|
||||
compose.abort_xhr();
|
||||
compose.abort_video_callbacks(undefined);
|
||||
compose_state.set_message_type(false);
|
||||
|
|
|
@ -3,6 +3,11 @@ import $ from "jquery";
|
|||
import render_compose_banner from "../templates/compose_banner/compose_banner.hbs";
|
||||
import render_stream_does_not_exist_error from "../templates/compose_banner/stream_does_not_exist_error.hbs";
|
||||
|
||||
export let scroll_to_message_banner_message_id: number | null = null;
|
||||
export function set_scroll_to_message_banner_message_id(val: number | null): void {
|
||||
scroll_to_message_banner_message_id = val;
|
||||
}
|
||||
|
||||
// banner types
|
||||
export const WARNING = "warning";
|
||||
export const ERROR = "error";
|
||||
|
@ -42,6 +47,7 @@ export function clear_message_sent_banners(): void {
|
|||
for (const classname of Object.values(MESSAGE_SENT_CLASSNAMES)) {
|
||||
$(`#compose_banners .${classname}`).remove();
|
||||
}
|
||||
scroll_to_message_banner_message_id = null;
|
||||
}
|
||||
|
||||
// TODO: Replace with compose_ui.hide_compose_spinner() when it is converted to ts.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import $ from "jquery";
|
||||
import _ from "lodash";
|
||||
|
||||
import * as compose_banner from "./compose_banner";
|
||||
import * as floating_recipient_bar from "./floating_recipient_bar";
|
||||
import * as hash_util from "./hash_util";
|
||||
import * as loading from "./loading";
|
||||
|
@ -9,7 +10,6 @@ import * as message_lists from "./message_lists";
|
|||
import * as message_viewport from "./message_viewport";
|
||||
import * as narrow_banner from "./narrow_banner";
|
||||
import * as narrow_state from "./narrow_state";
|
||||
import * as notifications from "./notifications";
|
||||
import * as recent_topics_util from "./recent_topics_util";
|
||||
import * as unread from "./unread";
|
||||
import * as unread_ops from "./unread_ops";
|
||||
|
@ -195,12 +195,12 @@ export function scroll_finished() {
|
|||
return;
|
||||
}
|
||||
|
||||
if (notifications.scroll_to_message_banner_message_id !== null) {
|
||||
if (compose_banner.scroll_to_message_banner_message_id !== null) {
|
||||
const $message_row = message_lists.current.get_row(
|
||||
notifications.scroll_to_message_banner_message_id,
|
||||
compose_banner.scroll_to_message_banner_message_id,
|
||||
);
|
||||
if ($message_row.length > 0 && !message_viewport.is_message_below_viewport($message_row)) {
|
||||
notifications.clear_compose_notifications();
|
||||
compose_banner.clear_message_sent_banners();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import {all_messages_data} from "./all_messages_data";
|
|||
import * as blueslip from "./blueslip";
|
||||
import * as channel from "./channel";
|
||||
import * as compose_actions from "./compose_actions";
|
||||
import * as compose_banner from "./compose_banner";
|
||||
import * as compose_closed_ui from "./compose_closed_ui";
|
||||
import * as compose_fade from "./compose_fade";
|
||||
import * as compose_state from "./compose_state";
|
||||
|
@ -417,7 +418,7 @@ export function activate(raw_operators, opts) {
|
|||
|
||||
// most users aren't going to send a bunch of a out-of-narrow messages
|
||||
// and expect to visit a list of narrows, so let's get these out of the way.
|
||||
notifications.clear_compose_notifications();
|
||||
compose_banner.clear_message_sent_banners();
|
||||
|
||||
// Open tooltips are only interesting for current narrow,
|
||||
// so hide them when activating a new one.
|
||||
|
|
|
@ -164,8 +164,6 @@ export function is_window_focused() {
|
|||
return window_focused;
|
||||
}
|
||||
|
||||
export let scroll_to_message_banner_message_id = null;
|
||||
|
||||
export function notify_above_composebox(
|
||||
banner_text,
|
||||
classname,
|
||||
|
@ -182,7 +180,7 @@ export function notify_above_composebox(
|
|||
link_text,
|
||||
}),
|
||||
);
|
||||
clear_compose_notifications();
|
||||
compose_banner.clear_message_sent_banners();
|
||||
$("#compose_banners").append($notification);
|
||||
}
|
||||
|
||||
|
@ -626,7 +624,7 @@ export function notify_local_mixes(messages, need_user_to_scroll) {
|
|||
link_msg_id,
|
||||
link_text,
|
||||
);
|
||||
scroll_to_message_banner_message_id = link_msg_id;
|
||||
compose_banner.set_scroll_to_message_banner_message_id(link_msg_id);
|
||||
}
|
||||
|
||||
// This is the HAPPY PATH--for most messages we do nothing
|
||||
|
@ -684,11 +682,6 @@ export function notify_messages_outside_current_search(messages) {
|
|||
}
|
||||
}
|
||||
|
||||
export function clear_compose_notifications() {
|
||||
compose_banner.clear_message_sent_banners();
|
||||
scroll_to_message_banner_message_id = null;
|
||||
}
|
||||
|
||||
export function reify_message_id(opts) {
|
||||
const old_id = opts.old_id;
|
||||
const new_id = opts.new_id;
|
||||
|
@ -701,7 +694,7 @@ export function reify_message_id(opts) {
|
|||
|
||||
if (message_id === old_id) {
|
||||
$elem.data("message-id", new_id);
|
||||
scroll_to_message_banner_message_id = new_id;
|
||||
compose_banner.set_scroll_to_message_banner_message_id(new_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -724,7 +717,7 @@ export function register_click_handlers() {
|
|||
const message_id = $(e.currentTarget).data("message-id");
|
||||
message_lists.current.select_id(message_id);
|
||||
navigate.scroll_to_selected();
|
||||
clear_compose_notifications();
|
||||
compose_banner.clear_message_sent_banners();
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
},
|
||||
|
|
|
@ -61,6 +61,7 @@ EXEMPT_FILES = make_set(
|
|||
"static/js/click_handlers.js",
|
||||
"static/js/compose.js",
|
||||
"static/js/compose_actions.js",
|
||||
"static/js/compose_banner.ts",
|
||||
"static/js/compose_closed_ui.js",
|
||||
"static/js/compose_fade.js",
|
||||
"static/js/compose_state.js",
|
||||
|
|
Loading…
Reference in New Issue