From 32dd26f1aff0171b822e6103faca445373804de4 Mon Sep 17 00:00:00 2001 From: Kate Date: Fri, 6 Dec 2024 18:05:10 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BF=D1=80=D0=BE=D1=88=D0=BB=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D0=B5=D0=B5=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/data.js | 4 ++-- js/main.js | 7 ++++--- js/render-thumbnails.js | 26 ++++++++++++++++++++++++++ js/thumbnails.js | 22 ---------------------- 4 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 js/render-thumbnails.js delete mode 100644 js/thumbnails.js diff --git a/js/data.js b/js/data.js index c5962f6..d4d19cd 100644 --- a/js/data.js +++ b/js/data.js @@ -94,6 +94,6 @@ const createPhoto = () => { }; }; -const CreatePhotoList = () => Array.from({length: PHOTO_LIST_LENGTH}, createPhoto()); +const createPhotoList = () => Array.from({length: PHOTO_LIST_LENGTH}, createPhoto()); -export {CreatePhotoList}; +export {createPhotoList}; diff --git a/js/main.js b/js/main.js index 6285485..50f9477 100644 --- a/js/main.js +++ b/js/main.js @@ -1,5 +1,6 @@ import './util.js'; -import {CreatePhotoList} from './data.js'; -import './thumbnails.js'; +import {createPhotoList} from './data.js'; +import {renderThumbnails} from './render-thumbnails.js'; -console.log(CreatePhotoList()); +console.log(createPhotoList()); +console.log(renderThumbnails()); diff --git a/js/render-thumbnails.js b/js/render-thumbnails.js new file mode 100644 index 0000000..95ed049 --- /dev/null +++ b/js/render-thumbnails.js @@ -0,0 +1,26 @@ +import {createPhotoList} from './data.js'; + +const pictures = document.querySelector('.pictures'); +const thumbnailsTemplate = document.querySelector('#picture') + .content + .querySelector('.picture'); + +const usersThumbnails = createPhotoList (); + +const renderThumbnails = () => { + const usersThumbnailsFragment = document.createDocumentFragment(); + + usersThumbnails.forEach((photo) => { + const usersElement = thumbnailsTemplate.cloneNode(true); + usersElement.querySelector('.picture__img').src = photo.url; + usersElement.querySelector('.picture__img').alt = photo.description; + usersElement.querySelector('.picture__likes').textContent = photo.likes; + usersElement.querySelector('.picture__comments').textContent = photo.comments.length; + usersThumbnailsFragment.appendChild(usersElement); + }); + + pictures.appendChild(usersThumbnailsFragment); + +}; + +export {renderThumbnails}; diff --git a/js/thumbnails.js b/js/thumbnails.js deleted file mode 100644 index ee29566..0000000 --- a/js/thumbnails.js +++ /dev/null @@ -1,22 +0,0 @@ -import {CreatePhotoList} from './data.js'; - -const pictures = document.querySelector('.pictures'); -const thumbnailsTemplate = document.querySelector('#picture') - .content - .querySelector('.picture'); - -const usersThumbnails = CreatePhotoList (); - -const usersThumbnailsFragment = document.createDocumentFragment(); - -usersThumbnails.forEach((photo) => { - const usersElement = thumbnailsTemplate.cloneNode(true); - usersElement.querySelector('.picture__img').src = photo.url; - usersElement.querySelector('.picture__img').alt = photo.description; - usersElement.querySelector('.picture__likes').textContent = photo.likes; - usersElement.querySelector('.picture__comments').textContent = photo.comments.length; - usersThumbnailsFragment.appendChild(usersElement); -}); - -pictures.appendChild(usersThumbnailsFragment); -