From d897d2e64efe74e6a7fa7abcae141834b046f3d5 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 29 Feb 2024 00:13:57 +0700 Subject: [PATCH 1/2] fix: Selected category is not ticked when it appears in the search result --- src/libs/OptionsListUtils.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 9121eebb3367..30accf449368 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -964,7 +964,12 @@ function getCategoryListSections( } if (searchInputValue) { - const searchCategories = enabledCategories.filter((category) => category.name.toLowerCase().includes(searchInputValue.toLowerCase())); + const searchCategories = enabledCategories + .filter((category) => category.name.toLowerCase().includes(searchInputValue.toLowerCase())) + .map((category) => ({ + ...category, + isSelected: selectedOptions.some((selectedOption) => selectedOption.name === category.name), + })); categorySections.push({ // "Search" section From bbcaad47a5cbec479f5ee03efa323a94edfd361b Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 4 Mar 2024 15:43:37 +0700 Subject: [PATCH 2/2] Optimize logic get search categories --- src/libs/OptionsListUtils.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.ts b/src/libs/OptionsListUtils.ts index 30accf449368..977770e08ad1 100644 --- a/src/libs/OptionsListUtils.ts +++ b/src/libs/OptionsListUtils.ts @@ -964,12 +964,17 @@ function getCategoryListSections( } if (searchInputValue) { - const searchCategories = enabledCategories - .filter((category) => category.name.toLowerCase().includes(searchInputValue.toLowerCase())) - .map((category) => ({ + const searchCategories: Category[] = []; + + enabledCategories.forEach((category) => { + if (!category.name.toLowerCase().includes(searchInputValue.toLowerCase())) { + return; + } + searchCategories.push({ ...category, isSelected: selectedOptions.some((selectedOption) => selectedOption.name === category.name), - })); + }); + }); categorySections.push({ // "Search" section