Skip to content

Commit a0b86bc

Browse files
committed
Refactor no results logic
1 parent db6f4c5 commit a0b86bc

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

site/src/component/SearchHitContainer/SearchHitContainer.tsx

+13-18
Original file line numberDiff line numberDiff line change
@@ -44,27 +44,22 @@ const SearchHitContainer: FC<SearchHitContainerProps> = ({ index, CourseHitItem,
4444
throw 'Professor Component not provided';
4545
}
4646

47-
function NoResults() {
48-
// prevent no results from showing when page is first loaded
49-
// (no results have been fetched yet for initial blank search query)
50-
// also prevent if names is not empty (search has been made, awaiting results)
51-
if (isFirstRender || names.length > 0) {
52-
return;
53-
}
54-
55-
return (
56-
<div className="no-results">
57-
<img src={noResultsImg} alt="No results found" />
58-
Sorry, we couldn't find any results for that search!
59-
</div>
60-
);
61-
}
47+
/**
48+
* if its first render, we are waiting for initial results
49+
* if names is non-empty but results is empty, we are waiting for results
50+
* otherwise, if results is still empty, we have no results for the search
51+
*/
52+
const noResults = results.length === 0 && !(isFirstRender || names.length > 0);
6253

6354
return (
6455
<div ref={containerDivRef} className="search-hit-container">
65-
{results.length === 0 ? (
66-
<NoResults />
67-
) : (
56+
{noResults && (
57+
<div className="no-results">
58+
<img src={noResultsImg} alt="No results found" />
59+
Sorry, we couldn't find any results for that search!
60+
</div>
61+
)}
62+
{results.length > 0 && (
6863
<SearchResults
6964
index={index}
7065
results={results}

0 commit comments

Comments
 (0)