From 5683cc0de2f2cbea220a800322ce0fc0c4d84a69 Mon Sep 17 00:00:00 2001 From: skyfxllen Date: Wed, 4 Dec 2024 20:27:19 +0700 Subject: [PATCH 1/3] module7 --- js/main.js | 4 +--- js/photos.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 js/photos.js diff --git a/js/main.js b/js/main.js index ff86c58..a7d0bfb 100644 --- a/js/main.js +++ b/js/main.js @@ -1,4 +1,2 @@ -import {createArrayOfPhotos} from './data.js'; - -createArrayOfPhotos(); +import './photos.js'; diff --git a/js/photos.js b/js/photos.js new file mode 100644 index 0000000..502cd67 --- /dev/null +++ b/js/photos.js @@ -0,0 +1,18 @@ +import {createArrayOfPhotos} from "./data.js"; +const picturesContainer = document.querySelector(".pictures"); +const pictureTemplate = document.querySelector("#picture").content.querySelector(".picture"); +const pictureFragment = document.createDocumentFragment(); + +const photos = createArrayOfPhotos(); + +photos.forEach((photo) => { + const picture = pictureTemplate.cloneNode(true); + + picture.querySelector(".picture__img").src = photo.url; + picture.querySelector(".picture__comments").textContent = photo.comments.length; + picture.querySelector(".picture__likes").textContent = photo.likes; + + pictureFragment.append(picture); +}); + +picturesContainer.append(pictureFragment); From 91d13013fe5386935c922981758acfcc628eccac Mon Sep 17 00:00:00 2001 From: Anton <79142916+skyfxllen@users.noreply.github.com> Date: Mon, 9 Dec 2024 12:58:46 +0700 Subject: [PATCH 2/3] module7 fixes --- js/main.js | 3 ++- js/photos.js | 30 ++++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/js/main.js b/js/main.js index a7d0bfb..3a68083 100644 --- a/js/main.js +++ b/js/main.js @@ -1,2 +1,3 @@ -import './photos.js'; +import {generatePictures} from './photos.js'; +generatePictures(); diff --git a/js/photos.js b/js/photos.js index 502cd67..455745c 100644 --- a/js/photos.js +++ b/js/photos.js @@ -1,18 +1,24 @@ import {createArrayOfPhotos} from "./data.js"; -const picturesContainer = document.querySelector(".pictures"); -const pictureTemplate = document.querySelector("#picture").content.querySelector(".picture"); -const pictureFragment = document.createDocumentFragment(); -const photos = createArrayOfPhotos(); +export function generatePictures(){ + const picturesContainer = document.querySelector(".pictures"); + const pictureTemplate = document.querySelector("#picture").content.querySelector(".picture"); + const pictureFragment = document.createDocumentFragment(); -photos.forEach((photo) => { - const picture = pictureTemplate.cloneNode(true); + const photos = createArrayOfPhotos(); - picture.querySelector(".picture__img").src = photo.url; - picture.querySelector(".picture__comments").textContent = photo.comments.length; - picture.querySelector(".picture__likes").textContent = photo.likes; + photos.forEach((photo) => { + const {url, description, comments, likes} = photo; + const picture = pictureTemplate.cloneNode(true); - pictureFragment.append(picture); -}); + picture.querySelector(".picture__img").src = url; + picture.querySelector(".picture__img").alt = description; + picture.querySelector(".picture__comments").textContent = comments.length; + picture.querySelector(".picture__likes").textContent = likes; + + pictureFragment.append(picture); + }); + + picturesContainer.append(pictureFragment); +} -picturesContainer.append(pictureFragment); From da998ba0a07d80206f3697c1355c65595af96ddc Mon Sep 17 00:00:00 2001 From: Anton <79142916+skyfxllen@users.noreply.github.com> Date: Tue, 10 Dec 2024 09:40:55 +0700 Subject: [PATCH 3/3] module7 fixes --- js/data.js | 10 +++++----- js/main.js | 2 +- js/{photos.js => pictures.js} | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) rename js/{photos.js => pictures.js} (85%) diff --git a/js/data.js b/js/data.js index da32757..56f635a 100644 --- a/js/data.js +++ b/js/data.js @@ -1,18 +1,18 @@ import {getARandomNumber} from './utils.js'; import {names, comments, descriptions} from './constants.js'; -export function createArrayOfPhotos(){ - const photos = []; +export function createArrayOfPictures(){ + const pictures = []; for (let i = 0; i < 25; i++){ - const newPhoto = { + const newPicture = { id : i + 1, url: `photos/${i + 1}.jpg`, description: descriptions[getARandomNumber(descriptions.length)], likes: getARandomNumber(200, 15), comments: createArrayOfComments(), }; - photos.push(newPhoto); + pictures.push(newPicture); } - return photos; + return pictures; } export function createArrayOfComments(){ diff --git a/js/main.js b/js/main.js index 3a68083..8fb354f 100644 --- a/js/main.js +++ b/js/main.js @@ -1,3 +1,3 @@ -import {generatePictures} from './photos.js'; +import {generatePictures} from './pictures.js'; generatePictures(); diff --git a/js/photos.js b/js/pictures.js similarity index 85% rename from js/photos.js rename to js/pictures.js index 455745c..096af8f 100644 --- a/js/photos.js +++ b/js/pictures.js @@ -1,13 +1,13 @@ -import {createArrayOfPhotos} from "./data.js"; +import {createArrayOfPictures} from "./data.js"; export function generatePictures(){ const picturesContainer = document.querySelector(".pictures"); const pictureTemplate = document.querySelector("#picture").content.querySelector(".picture"); const pictureFragment = document.createDocumentFragment(); - const photos = createArrayOfPhotos(); + const pictures = createArrayOfPictures(); - photos.forEach((photo) => { + pictures.forEach((photo) => { const {url, description, comments, likes} = photo; const picture = pictureTemplate.cloneNode(true);