generated from RealDevSquad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathUsersSection.js
More file actions
53 lines (50 loc) · 1.19 KB
/
UsersSection.js
File metadata and controls
53 lines (50 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { createElement } = react;
import { LoadingSpinner } from './LoadingSpinner.js';
export const UsersSection = ({
users,
showUser,
handleUserSelected,
paginateFetchedUsers,
activeTab,
currentPage,
isLoading,
}) => {
window.addEventListener(
'scroll',
debounce(() => {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight) {
paginateFetchedUsers(activeTab, currentPage + 1);
}
}, 200),
);
if (isLoading) {
return LoadingSpinner();
}
return createElement(
'aside',
{
class: 'users_section',
'data-testid': 'users-section',
},
users?.map((user) => {
return createElement(
'div',
{
class: `user_card ${
users[showUser].id === user.id ? 'active_tab' : ''
}`,
'data-testid': `user-card-${user.id}`,
'data-key': user.id,
onclick: () => handleUserSelected(user.id),
},
[
createElement('img', {
src: user?.picture?.url ?? dummyPicture,
class: 'user_image',
}),
createElement('span', {}, [user.first_name + ' ' + user.last_name]),
],
);
}),
);
};