Skip to content

Commit

Permalink
added render-pictures module
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil888-m committed Dec 5, 2024
1 parent b18ff7e commit bec6cbc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPhotos } from './get-photos.js';
import { renderPictures } from './render-pictures.js';

getPhotos();
renderPictures();

24 changes: 24 additions & 0 deletions js/render-pictures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { getPhotos } from './get-photos.js';

function renderPictures() {
const photos = getPhotos();
const pictureTemplate = document.querySelector('#picture').content.querySelector('.picture');
const picturesList = document.querySelector('.pictures');

const picturesListFragment = document.createDocumentFragment();

photos.forEach((photo) => {
const photoElement = pictureTemplate.cloneNode(true);
const photoImg = photoElement.querySelector('img');
photoImg.src = photo.url;
photoImg.alt = photo.description;
photoElement.querySelector('.picture__comments').textContent = photo.comments.length;
photoElement.querySelector('.picture__likes').textContent = photo.likes;

picturesListFragment.append(photoElement);
});

picturesList.append(picturesListFragment);
}

export { renderPictures };

0 comments on commit bec6cbc

Please sign in to comment.