Skip to content

Commit eb3bd0f

Browse files
Ishan VeerIshan Veer
authored andcommitted
updated pagination function to get data from api and then paginate them on frontend
1 parent db348a9 commit eb3bd0f

File tree

3 files changed

+10
-517
lines changed

3 files changed

+10
-517
lines changed

users/discord/App.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TabsSection } from './components/TabsSection.js';
22
import { UsersSection } from './components/UsersSection.js';
33
import { UserDetailsSection } from './components/UserDetailsSection.js';
4-
import { getUsers, mockUsersData } from './utils/util.js';
4+
import { getUsers } from './utils/util.js';
55
import { NoUserFound } from './components/NoUserFound.js';
66

77
const { createElement, rerender } = react;
@@ -26,19 +26,21 @@ let showUser = 0;
2626
the API pagination issue is resolved. Currently testing pagination using mock data.
2727
*/
2828
// usersData[activeTab] = await getUsers(activeTab);
29+
// add feature flag(feature should be only visible when query params dev=true)
2930

30-
export const fetchUsers = async (tabId, page = 1) => {
31+
export const paginateFetchedUsers = async (tabId, page = 1) => {
3132
if (isLoading) {
3233
return;
3334
}
35+
usersData[activeTab] = await getUsers(activeTab);
3436

3537
isLoading = true;
3638

3739
try {
3840
const start = (page - 1) * INITIAL_USERS;
3941
const end = start + INITIAL_USERS;
4042

41-
const newUsers = mockUsersData[tabId].slice(start, end);
43+
const newUsers = usersData[tabId].slice(start, end);
4244

4345
if (newUsers.length > 0) {
4446
if (page === 1) {
@@ -99,7 +101,7 @@ export const App = () => {
99101
users,
100102
showUser,
101103
handleUserSelected,
102-
fetchUsers,
104+
paginateFetchedUsers,
103105
activeTab,
104106
currentPage,
105107
isLoading,
@@ -113,4 +115,4 @@ export const App = () => {
113115
]);
114116
};
115117

116-
fetchUsers(activeTab, 1);
118+
paginateFetchedUsers(activeTab, 1);

users/discord/components/UsersSection.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ export const UsersSection = ({
55
users,
66
showUser,
77
handleUserSelected,
8-
fetchUsers,
8+
paginateFetchedUsers,
99
activeTab,
1010
currentPage,
1111
isLoading,
1212
}) => {
1313
window.addEventListener(
1414
'scroll',
1515
debounce(() => {
16-
console.log('scroll triggered');
1716
if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
18-
fetchUsers(activeTab, currentPage + 1);
17+
paginateFetchedUsers(activeTab, currentPage + 1);
1918
}
2019
}, 200),
2120
);
@@ -44,7 +43,7 @@ export const UsersSection = ({
4443
src: user?.picture?.url ?? dummyPicture,
4544
class: 'user_image',
4645
}),
47-
createElement('span', {}, [user.username]),
46+
createElement('span', {}, [user.first_name + ' ' + user.last_name]),
4847
],
4948
);
5049
}),

0 commit comments

Comments
 (0)