From f157bfe181136c2b0e0ee83399854961648237ed Mon Sep 17 00:00:00 2001 From: evykassirer Date: Mon, 28 Oct 2024 17:02:14 -0700 Subject: [PATCH] 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. --- web/src/buddy_list.ts | 34 ++++++++++++++++----------------- web/templates/right_sidebar.hbs | 6 +++--- web/tests/activity.test.js | 1 - 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/web/src/buddy_list.ts b/web/src/buddy_list.ts index a024ca6878..c8631c0ee6 100644 --- a/web/src/buddy_list.ts +++ b/web/src/buddy_list.ts @@ -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 { diff --git a/web/templates/right_sidebar.hbs b/web/templates/right_sidebar.hbs index 460d7fa9db..7d6e80d695 100644 --- a/web/templates/right_sidebar.hbs +++ b/web/templates/right_sidebar.hbs @@ -21,15 +21,15 @@
-
    +
      -
        +
          -
            +