Skip to content

Commit

Permalink
chore(demo): improve visual feedback on empty results
Browse files Browse the repository at this point in the history
Closes #126

Enhance the feedback for the empty search results page in the demo:

- Displays "Enter Something to search" instead of "No results" when the results container is empty.
- When a search is performed and there are no results, the icon changes and the text
  "No results" is displayed.
  • Loading branch information
jboix authored and amtins committed Dec 11, 2023
1 parent c64a623 commit f3d82cc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
9 changes: 8 additions & 1 deletion demo/scss/search.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@

.results-container:empty:after {
font-family: var(--font-sans);
content: "No results";
content: "Enter Something to search";
}

.results-container:empty:before {
font-size: var(--size-9);
}

.results-container.no-results:empty {
@include material-icon('do_not_disturb_alt');
&:after {
content: "No results";
}
}
19 changes: 15 additions & 4 deletions demo/src/search/search-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,25 @@ class SearchPage {
const data = await ilProvider.search(bu, query, signal);

this.#fetchNextPage = data.next;
this.#resultsEl.replaceChildren(...this.createResultsEl(data.results));
this.#resultsEl.classList.add('fade-in');
this.#updateResults(data.results);
this.initIntersectionObserver();
this.initScrollToTopButton();
} finally {
spinner.remove();
}
}

/**
* Updates the results in the page.
*
* @param results {{ title: string, urn: string }[]} the results.
*/
#updateResults(results) {
this.#resultsEl.replaceChildren(...this.createResultsEl(results));
this.#resultsEl.classList.add('fade-in');
this.#resultsEl.classList.toggle('no-results', results.length === 0);
}

/**
* Clear the search results and intersection observer and aborts any ongoing search query.
*
Expand All @@ -219,6 +229,7 @@ class SearchPage {
this.#intersectionObserverComponent?.remove();
this.#intersectionObserverComponent = null;
this.#resultsEl.replaceChildren();
this.#resultsEl.classList.toggle('no-results', false);

return signal;
}
Expand Down Expand Up @@ -308,9 +319,9 @@ class SearchPage {
/**
* Creates and returns HTML elements for the search results based on the provided results data.
*
* @param {Object[]} results - An array of search results.
* @param {{ title: string, urn: string }[]} results - An array of search results.
*
* @returns {HTMLElement[]} - An array of HTML elements representing the search results.
* @returns {NodeListOf<ChildNode>} - An array of HTML elements representing the search results.
*/
createResultsEl(results) {
return parseHtml(results.map((r) => {
Expand Down

1 comment on commit f3d82cc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 98.37% 482/490
🟢 Branches 93.44% 228/244
🟢 Functions 100% 136/136
🟢 Lines 99.15% 465/469

Test suite run success

145 tests passing in 9 suites.

Report generated by 🧪jest coverage report action from f3d82cc

Please sign in to comment.