Skip to content

Commit

Permalink
[front/components/vaults] - fix: update member list correctly on search
Browse files Browse the repository at this point in the history
 - Replace the member list when a new search is initiated, ensuring that previous search results do not persist
 - Append new members to the list properly when paginating through search results, avoiding duplicates
  • Loading branch information
Jules authored and Jules committed Oct 21, 2024
1 parent 68123ab commit b2ad58c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions front/components/vaults/SearchMembersPopover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,23 @@ export function SearchMembersPopover({
useEffect(() => {
if (members && !isLoading) {
setAllMembers((prevMembers) => {
const newMembers = members.filter(
(member) =>
!prevMembers.some((prevMember) => prevMember.sId === member.sId)
);
return [...prevMembers, ...newMembers];
if (pagination.pageIndex === 0) {
// if it's the first page, replace all members
return members;
} else {
// otherwise, append new members
const newMembers = members.filter(
(member) =>
!prevMembers.some((prevMember) => prevMember.sId === member.sId)
);
return [...prevMembers, ...newMembers];
}
});
}
}, [members, isLoading]);
}, [members, isLoading, pagination.pageIndex]);

// effect to reset pagination when search term changes
useEffect(() => {
// reset allMembers and pagination when search term changes
setAllMembers([]);
setPagination(DefaultPagination);
}, [searchTerm]);

Expand Down

0 comments on commit b2ad58c

Please sign in to comment.