-
Notifications
You must be signed in to change notification settings - Fork 0
/
users.js
31 lines (22 loc) · 818 Bytes
/
users.js
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
import renderNavigation from './navigation.js';
import {createElement, createLinkList, fetchData} from './functions.js'
async function init (){
const users = await fetchData('https://jsonplaceholder.typicode.com/users?_embed=posts') ;
let usersWrapper = document.querySelector('#users-wrapper');
let pageTitle = createElement('h1', 'Users list:', 'page-title');
let usersData = users.map(user=>{
let userObj = {
id: user.id,
title:`${user.name} (${user.posts.length})`,
}
return userObj;
})
let usersListElement = createLinkList({
data: usersData,
path: 'user',
listClasses: ['users-list'],
itemClasses: ['user-item'],
})
usersWrapper.append(pageTitle, usersListElement);
}
init();