Skip to content

Commit 04a6e83

Browse files
authored
Merge pull request #7 from Julyova/module7-task1
2 parents 6b829bc + 7f447cb commit 04a6e83

3 files changed

Lines changed: 48 additions & 3 deletions

File tree

js/data.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const COMMENTS = [
99
'Лица у людей на фотке перекошены, как будто их избивают. Как можно было поймать такой неудачный момент?!',
1010
];
1111

12-
1312
const DESCRIPTIONS = [
1413
'Отличный день!',
1514
'Прекрасный вид',
@@ -21,5 +20,4 @@ const DESCRIPTIONS = [
2120
'Городские джунгли',
2221
];
2322

24-
2523
export { NAMES, COMMENTS, DESCRIPTIONS };

js/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
/* eslint-disable no-console */
22

33
import { getArrayMiniatures } from './createArrayMiniatures.js';
4-
console.log(getArrayMiniatures());
4+
import { renderPictures } from './pictures.js';
5+
6+
const pictures = getArrayMiniatures();
7+
renderPictures(pictures);
8+

js/pictures.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const picturesContainer = document.querySelector('.pictures');
2+
const pictureTemplate = document.querySelector('#picture').content.querySelector('.picture');
3+
4+
/**
5+
* Создает DOM-элемент миниатюры на основе шаблона #picture
6+
* @param {Object} data - Объект с данными фотографии
7+
* @param {string} data.url - Адрес изображения
8+
* @param {string} data.description - Описание изображения
9+
* @param {number} data.likes - Количество лайков
10+
* @param {Array} data.comments - Массив комментариев
11+
* @returns {HTMLElement} - DOM-элемент миниатюры
12+
*/
13+
14+
const createPictureElement = ({ url, description, likes, comments }) => {
15+
const pictureElement = pictureTemplate.cloneNode(true);
16+
17+
const pictureImg = pictureElement.querySelector('.picture__img');
18+
pictureImg.src = url;
19+
pictureImg.alt = description;
20+
21+
pictureElement.querySelector('.picture__likes').textContent = likes;
22+
pictureElement.querySelector('.picture__comments').textContent = comments.length;
23+
24+
return pictureElement;
25+
};
26+
27+
/**
28+
* Отрисовывает миниатюры фотографий в блок .pictures
29+
* @param {Array} pictures - Массив объектов с данными фотографий
30+
*/
31+
const renderPictures = (pictures) => {
32+
const fragment = document.createDocumentFragment();
33+
34+
pictures.forEach((picture) => {
35+
const pictureElement = createPictureElement(picture);
36+
fragment.appendChild(pictureElement);
37+
});
38+
39+
picturesContainer.innerHTML = '';
40+
picturesContainer.appendChild(fragment);
41+
};
42+
43+
export { renderPictures };

0 commit comments

Comments
 (0)