buddy_list: Simplify logic to update empty list placeholders.

Because we regularly change what we want the placeholder
text to be, as the user enters and exits search, it's simpler
to just not use `data-search-results-empty` and set up the
placeholder from the buddy list code directly. Previously we
were trying to sometimes use `data-search-results-empty` and
sometimes set it directly, which is more confusing and complex.
This commit is contained in:
evykassirer 2024-10-28 17:02:14 -07:00 committed by Tim Abbott
parent d0dc33d8da
commit f157bfe181
3 changed files with 20 additions and 21 deletions

View File

@ -330,27 +330,27 @@ export class BuddyList extends BuddyListConf {
}
}
$("#buddy-list-users-matching-view").attr(
"data-search-results-empty",
matching_view_empty_list_message,
);
if ($("#buddy-list-users-matching-view .empty-list-message").length) {
const empty_list_widget_html = render_empty_list_widget_for_list({
empty_list_message: matching_view_empty_list_message,
});
$("#buddy-list-users-matching-view").html(empty_list_widget_html);
function add_or_update_empty_list_placeholder(selector: string, message: string): void {
if (
$(selector).children().length === 0 ||
$(`${selector} .empty-list-message`).length
) {
const empty_list_widget_html = render_empty_list_widget_for_list({
empty_list_message: message,
});
$(selector).html(empty_list_widget_html);
}
}
$("#buddy-list-other-users").attr(
"data-search-results-empty",
add_or_update_empty_list_placeholder(
"#buddy-list-users-matching-view",
matching_view_empty_list_message,
);
add_or_update_empty_list_placeholder(
"#buddy-list-other-users",
other_users_empty_list_message,
);
if ($("#buddy-list-other-users .empty-list-message").length) {
const empty_list_widget_html = render_empty_list_widget_for_list({
empty_list_message: other_users_empty_list_message,
});
$("#buddy-list-other-users").html(empty_list_widget_html);
}
}
update_section_header_counts(): void {

View File

@ -21,15 +21,15 @@
<div id="buddy_list_wrapper" class="scrolling_list" data-simplebar data-simplebar-tab-index="-1">
<div id="buddy-list-participants-container" class="buddy-list-section-container">
<div class="buddy-list-subsection-header"></div>
<ul id="buddy-list-participants" class="buddy-list-section" data-search-results-empty="{{t 'None.' }}"></ul>
<ul id="buddy-list-participants" class="buddy-list-section"></ul>
</div>
<div id="buddy-list-users-matching-view-container" class="buddy-list-section-container">
<div class="buddy-list-subsection-header"></div>
<ul id="buddy-list-users-matching-view" class="buddy-list-section" data-search-results-empty="{{t 'None.' }}"></ul>
<ul id="buddy-list-users-matching-view" class="buddy-list-section"></ul>
</div>
<div id="buddy-list-other-users-container" class="buddy-list-section-container">
<div class="buddy-list-subsection-header"></div>
<ul id="buddy-list-other-users" class="buddy-list-section" data-search-results-empty="{{t 'None.' }}"></ul>
<ul id="buddy-list-other-users" class="buddy-list-section"></ul>
</div>
<div id="buddy_list_wrapper_padding"></div>
<div class="right-sidebar-shortcuts">

View File

@ -731,7 +731,6 @@ test("realm_presence_disabled", ({override}) => {
test("redraw_muted_user", () => {
muted_users.add_muted_user(mark.user_id);
activity_ui.redraw_user(mark.user_id);
assert.equal($("#buddy-list-users-matching-view").html(), "never-been-set");
});
test("update_presence_info", ({override, override_rewire}) => {