Skip to content

Commit

Permalink
minor addition: Add No results label on no match
Browse files Browse the repository at this point in the history
  • Loading branch information
BharatAtbrat committed Jul 25, 2024
1 parent a0fc66e commit 84afab8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Library/Library.blp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@ Adw.Window window {
halign: center;
margin-bottom: 24;
margin-top: 12;
orientation: vertical;

Label results_empty {
visible: false;
margin-top: 46;
margin-bottom: 70;
label: _("No results");
}

Label {
label: _("All examples are dedicated to the public domain\nand <b>can be used freely</b> under the terms of <a href=\"https://creativecommons.org/publicdomain/zero/1.0/\">CC0 1.0</a>");
Expand Down
9 changes: 7 additions & 2 deletions src/Library/Library.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function Library({ application }) {
search_entry,
dropdown_category,
dropdown_language,
results_empty,
} = objects;
window.application = application;
picture_illustration.set_resource(illustration);
Expand Down Expand Up @@ -97,7 +98,7 @@ export default function Library({ application }) {
function updateList() {
const search_term = search_entry.get_text().toLowerCase();
const visible_categories = new Set();

let results_found = false;
widgets_map.forEach(
({ entry_row, category_index, languages_index }, demo_name) => {
const category_match =
Expand All @@ -110,7 +111,10 @@ export default function Library({ application }) {
language_match &&
(search_term === "" || search_match);
entry_row.visible = is_match;
if (is_match) visible_categories.add(category_check[category_index]);
if (is_match) {
results_found = true;
visible_categories.add(category_check[category_index]);
}
},
);

Expand All @@ -123,6 +127,7 @@ export default function Library({ application }) {
search_term === "";
category_widget.visible = visible_categories.has(category_name);
});
results_empty.set_visible(!results_found);
}

search_entry.connect("search-changed", updateList);
Expand Down

0 comments on commit 84afab8

Please sign in to comment.