Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Infinite Scroll #2461

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 55 additions & 57 deletions src/screens/Users/Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ const Users = (): JSX.Element => {
};

const handleSorting = (option: string): void => {
setDisplayedUsers([]);
if (sortingOption !== option) {
setDisplayedUsers([]);
}
setHasMore(true);
setSortingOption(option);
};
Expand Down Expand Up @@ -256,7 +258,9 @@ const Users = (): JSX.Element => {
};

const handleFiltering = (option: string): void => {
setDisplayedUsers([]);
if (filteringOption !== option) {
setDisplayedUsers([]);
}
setFilteringOption(option);
};

Expand Down Expand Up @@ -414,63 +418,57 @@ const Users = (): JSX.Element => {
</div>
) : (
<div className={styles.listBox}>
{isLoading ? (
<TableLoader headerTitles={headerTitles} noOfRows={perPageResult} />
) : (
<InfiniteScroll
dataLength={
/* istanbul ignore next */
displayedUsers.length ?? 0
}
next={loadMoreUsers}
loader={
<TableLoader
noOfCols={headerTitles.length}
noOfRows={perPageResult}
/>
}
hasMore={hasMore}
className={styles.listBox}
data-testid="users-list"
endMessage={
<div className={'w-100 text-center my-4'}>
<h5 className="m-0 ">{tCommon('endOfResults')}</h5>
</div>
}
>
<Table className="mb-0" responsive>
<thead>
<tr>
{headerTitles.map((title: string, index: number) => {
<InfiniteScroll
dataLength={
/* istanbul ignore next */
displayedUsers.length ?? 0
}
next={loadMoreUsers}
loader={
<TableLoader
noOfCols={headerTitles.length}
noOfRows={perPageResult}
/>
}
hasMore={hasMore}
className={styles.listBox}
data-testid="users-list"
endMessage={
<div className={'w-100 text-center my-4'}>
<h5 className="m-0 ">{tCommon('endOfResults')}</h5>
</div>
}
>
<Table className="mb-0" responsive>
<thead>
<tr>
{headerTitles.map((title: string, index: number) => {
return (
<th key={index} scope="col">
{title}
</th>
);
})}
</tr>
</thead>
<tbody>
{usersData &&
displayedUsers.map(
(user: InterfaceQueryUserListItem, index: number) => {
return (
<th key={index} scope="col">
{title}
</th>
<UsersTableItem
key={user.user._id}
index={index}
resetAndRefetch={resetAndRefetch}
user={user}
loggedInUserId={loggedInUserId ? loggedInUserId : ''}
/>
);
})}
</tr>
</thead>
<tbody>
{usersData &&
displayedUsers.map(
(user: InterfaceQueryUserListItem, index: number) => {
return (
<UsersTableItem
key={user.user._id}
index={index}
resetAndRefetch={resetAndRefetch}
user={user}
loggedInUserId={
loggedInUserId ? loggedInUserId : ''
}
/>
);
},
)}
</tbody>
</Table>
</InfiniteScroll>
)}
},
)}
</tbody>
</Table>
</InfiniteScroll>
</div>
)}
</>
Expand Down
Loading