From 07596782ab091635a45547cc44e7812c5e64d69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Darveau?= Date: Mon, 6 Sep 2021 12:36:38 -0400 Subject: [PATCH] fix for default categories not being shown --- client/src/components/Home/Home.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/client/src/components/Home/Home.tsx b/client/src/components/Home/Home.tsx index 5f8473c..a3ee9b4 100644 --- a/client/src/components/Home/Home.tsx +++ b/client/src/components/Home/Home.tsx @@ -120,6 +120,14 @@ const Home = (props: ComponentProps): JSX.Element => { return [category]; }; + const categoryContainsItems = (category: Category, allItems: App[] | Bookmark[]): boolean => { + if (category.apps?.length > 0) return true; + if (category.id < 0) { // Is a default category + return allItems.findIndex((item: App | Bookmark) => item.categoryId === category.id) >= 0; + } + return false; + }; + return ( {searchConfig('hideSearch', 0) !== 1 ? ( @@ -152,7 +160,7 @@ const Home = (props: ComponentProps): JSX.Element => { category.isPinned && category.apps?.length > 0) + ? appCategories.filter((category: Category) => category.isPinned && categoryContainsItems(category, apps)) : searchInCategories(localSearch, appCategories) } apps={ @@ -181,7 +189,7 @@ const Home = (props: ComponentProps): JSX.Element => { category.isPinned && category.bookmarks?.length > 0) + ? bookmarkCategories.filter((category: Category) => category.isPinned && categoryContainsItems(category, bookmarks)) : searchInCategories(localSearch, bookmarkCategories) } bookmarks={