Unified bookmark search
This commit is contained in:
@@ -74,15 +74,32 @@ const BookmarkSettings = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (groupData && groupsIsFetched) {
|
||||
setGroups(
|
||||
groupData
|
||||
.filter((a: BookmarkGroup) =>
|
||||
a.categoryName.toLowerCase().includes(debouncedGroupSearch.toLowerCase()),
|
||||
)
|
||||
.sort((a: BookmarkGroup, b: BookmarkGroup) =>
|
||||
a.categoryIndex > b.categoryIndex ? 1 : -1,
|
||||
),
|
||||
const foundBookmarkGroups = [
|
||||
...new Set(
|
||||
bookmarks
|
||||
.filter(
|
||||
(a: Bookmark) =>
|
||||
a.name.toLowerCase().includes(debouncedGroupSearch.toLowerCase()) ||
|
||||
a.url.toLowerCase().includes(debouncedGroupSearch.toLowerCase()),
|
||||
)
|
||||
.map(
|
||||
(a: Bookmark) =>
|
||||
groupData.filter(
|
||||
(b: BookmarkGroup) =>
|
||||
b.categoryName.toLowerCase() === a.category.toLowerCase(),
|
||||
)[0],
|
||||
),
|
||||
),
|
||||
];
|
||||
const foundGroups = groupData.filter((a: BookmarkGroup) =>
|
||||
a.categoryName.toLowerCase().includes(debouncedGroupSearch.toLowerCase()),
|
||||
);
|
||||
|
||||
const groupList = [...new Set([...foundBookmarkGroups, ...foundGroups])].sort(
|
||||
(a: BookmarkGroup, b: BookmarkGroup) =>
|
||||
a.categoryIndex > b.categoryIndex ? 1 : -1,
|
||||
);
|
||||
setGroups(groupList);
|
||||
}
|
||||
}, [groupData, groupsIsFetched, debouncedGroupSearch]);
|
||||
|
||||
@@ -278,6 +295,7 @@ const BookmarkSettings = () => {
|
||||
bookmarks={bookmarks
|
||||
.filter((a: Bookmark) => a.category === group.categoryName)
|
||||
.sort((a: Bookmark, b: Bookmark) => (a.index > b.index ? 1 : -1))}
|
||||
searchTerm={searchValue}
|
||||
/>
|
||||
))}
|
||||
</Group>
|
||||
|
||||
Reference in New Issue
Block a user