narrow: Update narrow title for undefined filter views.

Updates `compute_narrow_title` to cover the two cases for views
with undefined filters: "All messages" and "Recent conversations".

Also, moves the call to `notifications.redraw_title` from
`set_narrow_title` and to `update_narrow_title`.
This commit is contained in:
Lauryn Menard 2022-12-15 15:22:33 +01:00 committed by Tim Abbott
parent 7686bca385
commit 7c083edb96
4 changed files with 27 additions and 9 deletions

View File

@ -22,6 +22,9 @@ const compose_pm_pill = mock_esm("../../static/js/compose_pm_pill");
mock_esm("../../static/js/spectators", {
login_to_access() {},
});
const recent_topics_util = mock_esm("../../static/js/recent_topics_util", {
is_visible() {},
});
function empty_narrow_html(title, html, search_data) {
const opts = {
@ -815,10 +818,18 @@ run_test("narrow_to_compose_target PMs", ({override, override_rewire}) => {
assert.deepEqual(args.operators, [{operator: "is", operand: "private"}]);
});
run_test("narrow_compute_title", () => {
run_test("narrow_compute_title", ({override}) => {
// Only tests cases where the narrow title is different from the filter title.
let filter;
// Recent conversations & All messages have `undefined` filter.
filter = undefined;
override(recent_topics_util, "is_visible", () => true);
assert.equal(narrow.compute_narrow_title(filter), "translated: Recent conversations");
override(recent_topics_util, "is_visible", () => false);
assert.equal(narrow.compute_narrow_title(filter), "translated: All messages");
// Search & uncommon narrows
filter = new Filter([{operator: "search", operand: "potato"}]);
assert.equal(narrow.compute_narrow_title(filter), "translated: Search results");

View File

@ -102,7 +102,7 @@ mock_esm("../../static/js/user_topics", {
},
});
const narrow = mock_esm("../../static/js/narrow", {
set_narrow_title: noop,
update_narrow_title: noop,
hide_mark_as_read_turned_off_banner: noop,
handle_middle_pane_transition: noop,
has_shown_message_list_view: true,

View File

@ -119,12 +119,20 @@ export function save_pre_narrow_offset_for_reload() {
export let narrow_title = "home";
export let has_shown_message_list_view = false;
export function set_narrow_title(title) {
function set_narrow_title(title) {
narrow_title = title;
notifications.redraw_title();
}
export function compute_narrow_title(filter) {
if (filter === undefined) {
// "All messages" and "Recent conversations" views have
// an `undefined` filter.
if (recent_topics_util.is_visible()) {
return $t({defaultMessage: "Recent conversations"});
}
return $t({defaultMessage: "All messages"});
}
const filter_title = filter.get_title();
if (filter_title === undefined) {
@ -162,9 +170,10 @@ export function compute_narrow_title(filter) {
return filter_title;
}
function update_narrow_title(filter) {
export function update_narrow_title(filter) {
const narrow_title_string = compute_narrow_title(filter);
set_narrow_title(narrow_title_string);
notifications.redraw_title();
}
export function reset_ui_state() {
@ -1007,8 +1016,7 @@ function handle_post_narrow_deactivate_processes() {
widgetize.set_widgets_for_list();
typing_events.render_notifications_for_narrow();
message_view_header.initialize();
narrow_title = $t({defaultMessage: "All messages"});
notifications.redraw_title();
update_narrow_title(narrow_state.filter());
message_scroll.update_top_of_narrow_notices(message_lists.home);
}

View File

@ -870,8 +870,7 @@ export function show() {
compose_closed_ui.update_buttons_for_recent_topics();
narrow_state.reset_current_filter();
const recent_topics_title = $t({defaultMessage: "Recent conversations"});
narrow.set_narrow_title(recent_topics_title);
narrow.update_narrow_title(narrow_state.filter());
message_view_header.render_title_area();
narrow.handle_middle_pane_transition();
pm_list.handle_narrow_deactivated();