Skip to content

Commit f359a31

Browse files
authored
Merge pull request #5 from Elvira-Nikolenko/module7-task1
2 parents 72136d4 + 2033976 commit f359a31

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

js/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import './thumbnails';
2+
13
const MIN_COUNT_ID = 1;
24
const MAX_COUNT_ID = 25;
35
const MAX_LENGTH_IMAGES = 25;
@@ -71,7 +73,7 @@ function getCommentsList(maxLength) {
7173
return commentsList;
7274
}
7375

74-
function getImageList(maxLength = MAX_LENGTH_IMAGES) {
76+
export function getImageList(maxLength = MAX_LENGTH_IMAGES) {
7577
const imagesList = [];
7678

7779
for (let i = 0; i < maxLength; i++) {

js/thumbnails.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import {getImageList} from './main';
2+
3+
const miniature = document.querySelector('#picture').content;
4+
5+
const renderMiniature = (dataUser) => {
6+
const newMiniature = miniature.cloneNode(true);
7+
const imagePath = newMiniature.querySelector('.picture__img');
8+
const likes = newMiniature.querySelector('.picture__likes');
9+
const comments = newMiniature.querySelector('.picture__comments');
10+
11+
imagePath.src = dataUser.url;
12+
likes.textContent = dataUser.likes;
13+
comments.textContent = dataUser.comments.length;
14+
15+
return newMiniature;
16+
};
17+
18+
const fragment = document.createDocumentFragment();
19+
const imageList = getImageList();
20+
21+
const renderListMiniature = (list) => {
22+
list.forEach((image) => {
23+
fragment.appendChild(renderMiniature(image));
24+
});
25+
26+
const pictureContainer = document.querySelector('.pictures');
27+
if (pictureContainer) {
28+
pictureContainer.appendChild(fragment);
29+
}
30+
};
31+
32+
renderListMiniature(imageList);

0 commit comments

Comments
 (0)