Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Отрисуй меня полностью #6

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions js/data.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import {getARandomNumber} from './utils.js';

Check warning on line 1 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Strings must use doublequote
import {names, comments, descriptions} from './constants.js';

Check warning on line 2 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Strings must use doublequote
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(){
Expand All @@ -22,7 +22,7 @@
const newComment = {
id: i + 1,
avatar: `img/avatar-${getARandomNumber(6, 1)}.svg`,
message: Array.from({ length: getARandomNumber(2, 1) }, () => comments[getARandomNumber(comments.length)]).join('\n'),

Check warning on line 25 in js/data.js

View workflow job for this annotation

GitHub Actions / Check

Strings must use doublequote
name: names[getARandomNumber(names.length)],
};
newComments.push(newComment);
Expand Down
5 changes: 2 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {createArrayOfPhotos} from './data.js';

createArrayOfPhotos();
import {generatePictures} from './pictures.js';

generatePictures();
24 changes: 24 additions & 0 deletions js/pictures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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 pictures = createArrayOfPictures();

pictures.forEach((photo) => {
const {url, description, comments, likes} = photo;
const picture = pictureTemplate.cloneNode(true);

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);
}

Loading