From af05d795e37f323fd364d5f9c6dd610a40576fe4 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Sat, 20 May 2023 22:07:10 +0100 Subject: [PATCH] Group separation, no result handling and filtering --- src/components/CommandMenu/CommandMenu.tsx | 66 ++++++++++++++-------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/src/components/CommandMenu/CommandMenu.tsx b/src/components/CommandMenu/CommandMenu.tsx index 822967dbb..f6ecf74fa 100644 --- a/src/components/CommandMenu/CommandMenu.tsx +++ b/src/components/CommandMenu/CommandMenu.tsx @@ -46,11 +46,13 @@ export function CommandMenu() { const normalizedSearchText = searchedText.trim().toLowerCase(); getAllPages().then((unfilteredPages = defaultPages) => { - const filteredPages = unfilteredPages.filter((currPage: PageType) => { - return ( - currPage.title.toLowerCase().indexOf(normalizedSearchText) !== -1 - ); - }); + const filteredPages = unfilteredPages + .filter((currPage: PageType) => { + return ( + currPage.title.toLowerCase().indexOf(normalizedSearchText) !== -1 + ); + }) + .slice(0, 10); setActiveCounter(0); setSearchResults(filteredPages); @@ -63,7 +65,7 @@ export function CommandMenu() { return (
-
+
- {searchResults.map((page, counter) => ( - setActiveCounter(counter)} - href={page.url} - > - {searchedText && ( - {page.group} - )} - {!searchedText && ( - ICON - )} - {page.title} - - ))} + {searchResults.length === 0 && ( +
+ No results found +
+ )} + + {searchResults.map((page, counter) => { + const prevPage = searchResults[counter - 1]; + const groupChanged = prevPage && prevPage.group !== page.group; + + return ( + <> + {groupChanged && ( +
+ )} + setActiveCounter(counter)} + href={page.url} + > + {searchedText && ( + {page.group} + )} + {!searchedText && ( + ICON + )} + {page.title} + + + ); + })}