Search bar fixes and performance updates
This commit is contained in:
@@ -33,14 +33,10 @@ const BookmarkSettings = () => {
|
||||
},
|
||||
});
|
||||
const bookmarksEndpoint = 'api/bookmarks';
|
||||
const {
|
||||
data: bookmarkData,
|
||||
isFetched: bookmarkDataIsFetched,
|
||||
isFetching: bookmarkDataIsFetching,
|
||||
} = useQueryAPI({
|
||||
const { data: bookmarkData, isFetching: bookmarkDataIsFetching } = useQueryAPI({
|
||||
endpoint: bookmarksEndpoint,
|
||||
});
|
||||
const [bookmarks, setBookmarks] = useState<Bookmark[]>([]);
|
||||
const bookmarks = bookmarkData || [];
|
||||
const categoriesEndpoint = 'api/bookmarkCategories';
|
||||
const { data: groupData, isFetched: groupsIsFetched } = useQueryAPI({
|
||||
endpoint: categoriesEndpoint,
|
||||
@@ -54,7 +50,27 @@ const BookmarkSettings = () => {
|
||||
const [debouncedGroupSearch] = useDebouncedValue(searchValue, 500);
|
||||
const [modalOpened, { open: openModal, close: closeModal }] = useDisclosure(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const foundBookmarkGroups = [
|
||||
...new Set(
|
||||
bookmarks
|
||||
.filter(
|
||||
(a: Bookmark) =>
|
||||
a.name
|
||||
.toLowerCase()
|
||||
.includes((debouncedGroupSearch as string).toLowerCase()) ||
|
||||
a.url.toLowerCase().includes((debouncedGroupSearch as string).toLowerCase()),
|
||||
)
|
||||
.map((a: Bookmark) =>
|
||||
groupData.find(
|
||||
(b: BookmarkGroup) =>
|
||||
b.categoryName.toLowerCase() === a.category.toLowerCase(),
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
const foundGroups = groupData.filter((a: BookmarkGroup) =>
|
||||
a.categoryName.toLowerCase().includes((debouncedGroupSearch as string).toLowerCase()),
|
||||
);
|
||||
const handleClose = () => {
|
||||
closeModal();
|
||||
form.reset();
|
||||
@@ -80,40 +96,8 @@ const BookmarkSettings = () => {
|
||||
);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (bookmarkData && bookmarkDataIsFetched) {
|
||||
setBookmarks(bookmarkData);
|
||||
}
|
||||
}, [bookmarkDataIsFetched, bookmarkData]);
|
||||
|
||||
useEffect(() => {
|
||||
if (groupData && groupsIsFetched) {
|
||||
const foundBookmarkGroups = [
|
||||
...new Set(
|
||||
bookmarks
|
||||
.filter(
|
||||
(a: Bookmark) =>
|
||||
a.name
|
||||
.toLowerCase()
|
||||
.includes((debouncedGroupSearch as string).toLowerCase()) ||
|
||||
a.url
|
||||
.toLowerCase()
|
||||
.includes((debouncedGroupSearch as string).toLowerCase()),
|
||||
)
|
||||
.map((a: Bookmark) =>
|
||||
groupData.find(
|
||||
(b: BookmarkGroup) =>
|
||||
b.categoryName.toLowerCase() === a.category.toLowerCase(),
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
const foundGroups = groupData.filter((a: BookmarkGroup) =>
|
||||
a.categoryName
|
||||
.toLowerCase()
|
||||
.includes((debouncedGroupSearch as string).toLowerCase()),
|
||||
);
|
||||
|
||||
const groupList = [...new Set([...foundBookmarkGroups, ...foundGroups])].sort(
|
||||
(a: BookmarkGroup, b: BookmarkGroup) =>
|
||||
a.categoryIndex > b.categoryIndex ? 1 : -1,
|
||||
|
||||
Reference in New Issue
Block a user