compose: Make stronger, more readable button-update logic.

This commit is contained in:
Karl Stolley 2023-10-04 11:36:15 -05:00 committed by Tim Abbott
parent c73de34f32
commit 0f084587e0
6 changed files with 10 additions and 8 deletions

View File

@ -119,7 +119,7 @@ export function update_buttons_for_private() {
update_buttons(text_stream, disable_reply);
}
export function update_buttons_for_stream() {
export function update_buttons_for_stream_views() {
const text_stream = $t({defaultMessage: "Start new conversation"});
$("#new_conversation_button").attr(
"data-tooltip-template-id",
@ -128,7 +128,7 @@ export function update_buttons_for_stream() {
update_buttons(text_stream);
}
export function update_buttons_for_recent_view() {
export function update_buttons_for_non_stream_views() {
const text_stream = $t({defaultMessage: "Start new conversation"});
$("#new_conversation_button").attr(
"data-tooltip-template-id",

View File

@ -926,8 +926,10 @@ function handle_post_view_change(msg_list) {
if (filter.contains_only_private_messages()) {
compose_closed_ui.update_buttons_for_private();
} else if (filter.is_conversation_view() || filter.includes_full_stream_history()) {
compose_closed_ui.update_buttons_for_stream_views();
} else {
compose_closed_ui.update_buttons_for_stream();
compose_closed_ui.update_buttons_for_non_stream_views();
}
compose_closed_ui.update_reply_recipient_label();

View File

@ -918,7 +918,7 @@ export function show() {
// We want to show `new stream message` instead of
// `new topic`, which we are already doing in this
// function. So, we reuse it here.
update_compose: compose_closed_ui.update_buttons_for_recent_view,
update_compose: compose_closed_ui.update_buttons_for_non_stream_views,
is_recent_view: true,
is_visible,
set_visible,

View File

@ -784,7 +784,7 @@ test_ui("narrow_button_titles", ({override}) => {
$t({defaultMessage: "New direct message"}),
);
compose_closed_ui.update_buttons_for_stream();
compose_closed_ui.update_buttons_for_stream_views();
assert.equal(
$("#new_conversation_button").text(),
$t({defaultMessage: "Start new conversation"}),

View File

@ -95,7 +95,7 @@ function test_helper({override}) {
stub(left_sidebar_navigation_area, "handle_narrow_activated");
stub(typing_events, "render_notifications_for_narrow");
stub(unread_ops, "process_visible");
stub(compose_closed_ui, "update_buttons_for_stream");
stub(compose_closed_ui, "update_buttons_for_stream_views");
stub(compose_closed_ui, "update_buttons_for_private");
// We don't test the css calls; we just skip over them.
$("#mark_read_on_scroll_state_banner").toggleClass = () => {};
@ -194,7 +194,7 @@ run_test("basics", ({override}) => {
[message_viewport, "stop_auto_scrolling"],
[browser_history, "set_hash"],
[typing_events, "render_notifications_for_narrow"],
[compose_closed_ui, "update_buttons_for_stream"],
[compose_closed_ui, "update_buttons_for_stream_views"],
[compose_closed_ui, "update_reply_recipient_label"],
[message_view_header, "render_title_area"],
[narrow_title, "update_narrow_title"],

View File

@ -89,7 +89,7 @@ const ListWidget = mock_esm("../src/list_widget", {
mock_esm("../src/compose_closed_ui", {
set_standard_text_for_reply_button: noop,
update_buttons_for_recent_view: noop,
update_buttons_for_non_stream_views: noop,
});
mock_esm("../src/hash_util", {
by_stream_url: test_url,