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 1 commit
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
4 changes: 1 addition & 3 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
import {createArrayOfPhotos} from './data.js';

createArrayOfPhotos();
import './photos.js';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Когда создашь функцию в модуле, стоит импортировать ее и вызвать в главном модуле)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправил)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

18 changes: 18 additions & 0 deletions js/photos.js

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше всего стараться всегда писать весь код внутри функций. Даже если в файле больше нет функций. Так проще масштабировать код, экспортировать, изолировать переменные. Поэтому здесь тоже лучше создать как минимум одну функцию для создания мениатюр. Может быть ты захочешь создать и больше, чем одну, почему нет)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Original file line number Diff line number Diff line change
@@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У фото еще alt нужно заполнить по заданию

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

как-то пропустил, исправил)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

picture.querySelector(".picture__comments").textContent = photo.comments.length;
picture.querySelector(".picture__likes").textContent = photo.likes;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно в начале развернуть массив, чтобы проще было обращаться ко всем свойствам. Пример const [likes] = photo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Заметил мою ошибку с массивом) Конечно же у нас объект, сделал все правильно
👍🏻


pictureFragment.append(picture);
});

picturesContainer.append(pictureFragment);
Loading