Skip to content

Commit

Permalink
Вносит правки в решение
Browse files Browse the repository at this point in the history
  • Loading branch information
harl-i committed Jan 13, 2025
1 parent 63e8bd9 commit 071ae71
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 71 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<title>Кексограм</title>
<title>Кекстаграм</title>
</head>

<body>
Expand Down
56 changes: 56 additions & 0 deletions js/big-photo-viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {fillCommentsList} from './comments-viewer.js';

const picturesContainerElement = document.querySelector('.pictures');
const bigPhotoElement = document.querySelector('.big-picture');

const bodyElement = document.body;
let photoData = [];

picturesContainerElement.addEventListener('click', (evt) => {
const targetPhotoId = evt.target.closest('.picture');
const targetPhoto = photoData.find((photo) => photo.photoId === Number(targetPhotoId.dataset.photoId));
const {url, description, likes, comments} = targetPhoto;

bigPhotoElement.querySelector('.social__comment-count').classList.add('hidden');
bigPhotoElement.querySelector('.comments-loader').classList.add('hidden');

bigPhotoElement.querySelector('img').setAttribute('src', url);
bigPhotoElement.querySelector('.likes-count').textContent = likes;
bigPhotoElement.querySelector('.social__comment-total-count').textContent = comments.length;
bigPhotoElement.querySelector('.social__caption').textContent = description;

bigPhotoElement.classList.remove('hidden');
bodyElement.classList.add('modal-open');

fillCommentsList(targetPhoto.comments);

bigPhotoElement.querySelector('.social__comment-shown-count').textContent = comments.length;

bigPhotoElement.setAttribute('tabindex', '0');
bigPhotoElement.focus();
});

bigPhotoElement.addEventListener('click', (evt) => {
if(evt.target.closest('.big-picture__cancel')) {
closeBigPhoto();
}
});

bigPhotoElement.addEventListener('keydown', (evt) => {
if (evt.key === 'Escape') {
closeBigPhoto();
}
});

function closeBigPhoto() {
bigPhotoElement.classList.add('hidden');
bodyElement.classList.remove('modal-open');
}

function setPhotoData(data) {
photoData = data;
}

export {setPhotoData};


57 changes: 0 additions & 57 deletions js/bigPhotoViewer.js

This file was deleted.

2 changes: 1 addition & 1 deletion js/comments.js → js/comments-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const AVATARS_COUNT = {
};

const SENTENCES_COUNT = {
MIN: 0,
MIN: 1,
MAX: 2
};

Expand Down
17 changes: 17 additions & 0 deletions js/comments-viewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const socialCommentsElement = document.querySelector('.social__comments');
const commentTemplateElement = socialCommentsElement.querySelector('.social__comment');

function fillCommentsList(comments) {
socialCommentsElement.innerHTML = '';
comments.forEach((comment) => {
const newCommentElement = commentTemplateElement.cloneNode(true);
const commentPictureElement = newCommentElement.querySelector('.social__picture');

commentPictureElement.setAttribute('src', comment.avatar);
commentPictureElement.setAttribute('alt', comment.name);
newCommentElement.querySelector('.social__text').textContent = comment.commentsList;
socialCommentsElement.appendChild(newCommentElement);
});
}

export {fillCommentsList};
39 changes: 35 additions & 4 deletions js/data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {generateUniqueInteger, getRandomInteger} from './util.js';
import {getRandomComments} from './comments.js';
import {getRandomComments} from './comments-data.js';

const LIKES_COUNT = {
MIN: 15,
Expand Down Expand Up @@ -28,7 +28,34 @@ const PHOTO_DESCRIPTIONS = ['Закат над океаном',
'Маленькая хижина в горах', 'Закат в тропиках', 'Стадо оленей на рассвете', 'Городской парк с фонтаном',
'Облачный горизонт над мегаполисом', 'Гребной канал с лодками', 'Старинный замок в горах'];

const photoData = (function getPhotoData(objectsCount) {
let photoData = [];

// const photoData = (function getPhotoData(objectsCount) {
// const objects = [];
// const getUniquePhotoIdValue = generateUniqueInteger(getRandomInteger, ID_RANGE.MIN, ID_RANGE.MAX);
// const getUniqueUrlValue = generateUniqueInteger(getRandomInteger, URL_RANGE.MIN, URL_RANGE.MAX);
//
// for (let i = 0; i < objectsCount - 1; i++) {
// const comments = getRandomComments();
//
// const photoId = getUniquePhotoIdValue();
// const url = `photos/${getUniqueUrlValue()}.jpg`;
// const description = PHOTO_DESCRIPTIONS[getRandomInteger(0, PHOTO_DESCRIPTIONS.length - 1)];
// const likes = getRandomInteger(LIKES_COUNT.MIN, LIKES_COUNT.MAX);
//
// objects.push({
// photoId,
// url,
// description,
// likes,
// comments
// });
// }
//
// return objects;
// })(26);

function getPhotoData(objectsCount) {
const objects = [];
const getUniquePhotoIdValue = generateUniqueInteger(getRandomInteger, ID_RANGE.MIN, ID_RANGE.MAX);
const getUniqueUrlValue = generateUniqueInteger(getRandomInteger, URL_RANGE.MIN, URL_RANGE.MAX);
Expand All @@ -51,6 +78,10 @@ const photoData = (function getPhotoData(objectsCount) {
}

return objects;
})(26);
}

function generateMockData(count) {
photoData = getPhotoData(count);
}

export {photoData};
export {photoData, generateMockData};
9 changes: 6 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import './data.js';
import {photoData, generateMockData} from './data.js';
import {showThumbnail} from './thumbnails.js';
import './bigPhotoViewer.js';
import {setPhotoData} from './big-photo-viewer.js';

generateMockData(26);
showThumbnail(photoData);
setPhotoData(photoData);

showThumbnail();
8 changes: 3 additions & 5 deletions js/thumbnails.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {photoData} from './data.js';

const pictureTemplateElement = document.querySelector('#picture').content.querySelector('.picture');
const picturesContainer = document.querySelector('.pictures');

function showThumbnail() {
function showThumbnail(photoData) {
const fragment = document.createDocumentFragment();

photoData.forEach(({photoId ,url, description, likes, comments }) => {
const pictureElement = pictureTemplateElement.cloneNode(true);

pictureElement.dataset.photoId = photoId;
pictureElement.querySelector('img').src = url;
pictureElement.querySelector('img').alt = description;
pictureElement.querySelector('img').setAttribute('src', url);
pictureElement.querySelector('img').setAttribute('alt', description);
pictureElement.querySelector('.picture__comments').textContent = comments.length;
pictureElement.querySelector('.picture__likes').textContent = likes;

Expand Down

0 comments on commit 071ae71

Please sign in to comment.