Skip to content

Commit

Permalink
Merge pull request #53 from engagingnewsproject/revert-52-lazy-load
Browse files Browse the repository at this point in the history
Revert "Added lazy load to user list dashboard"
  • Loading branch information
luukee authored Oct 22, 2024
2 parents 7d6c6f3 + 8458edb commit 846e532
Showing 1 changed file with 1 addition and 42 deletions.
43 changes: 1 addition & 42 deletions components/Users.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,45 +93,6 @@ const sortByJoinedDate = (users) => {

const Users = () => {
// Initialize authentication context
const [hasMore, setHasMore] = useState(true);
const [page, setPage] = useState(0);
const pageSize = 10;

const fetchMoreData = async () => {
if (isLoading) return;

setIsLoading(true);
try {
const mobileUsersQuerySnapshot = await getDocs(
query(
collection(db, 'mobileUsers'),
limit(pageSize),
startAfter(page * pageSize)
)
);

const newUsers = await Promise.all(
mobileUsersQuerySnapshot.docs.map(async (doc) => {
const userData = doc.data();
userData.mobileUserId = doc.id;
userData.disabled = await fetchUserDetails(doc.id);
userData.joined = getJoinedDate(userData, null);
return userData;
})
);

if (newUsers.length < pageSize) {
setHasMore(false);
}

setLoadedMobileUsers((prevUsers) => [...prevUsers, ...newUsers]);
setPage((prevPage) => prevPage + 1);
} catch (error) {
console.error('Failed to fetch more user data:', error);
} finally {
setIsLoading(false);
}
};
const {
user,
addAdminRole,
Expand Down Expand Up @@ -887,9 +848,7 @@ const Users = () => {
className="overflow-x-auto"
dataLength={endIndex}
inverse={false}
scrollableTarget="scrollableDiv"
next={fetchMoreData}
hasMore={hasMore}>
scrollableTarget="scrollableDiv">
<table className="min-w-full bg-white rounded-xl p-1">
<thead className="border-b dark:border-indigo-100 bg-slate-100">
<tr>
Expand Down

0 comments on commit 846e532

Please sign in to comment.