Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Khrulev committed Dec 5, 2024
1 parent 7d995f1 commit d08f4e7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
1 change: 0 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import './post.js';
import { createMockPosts } from './mock.js';
import { printThumbnails } from './thumbnails.js';
import { picturesContainer } from './thumbnails.js';
Expand Down
17 changes: 9 additions & 8 deletions js/post.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { escKeypress } from './utils';

const postModal = document.querySelector('.big-picture');
const closeModalBtn = document.querySelector('.big-picture__cancel');
const postComments = document.querySelector('.social__comments');
Expand All @@ -9,11 +11,6 @@ const closePostModal = () => {
document.body.classList.remove('modal-open');
};

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

const insertPostComments = (commentsArr) => {
const commentsFragment = document.createDocumentFragment();
Expand All @@ -33,6 +30,7 @@ const insertPostComments = (commentsArr) => {
};

const openPostModal = (content) => {
postModal.classList.remove('hidden');
document.body.classList.add('modal-open');
postModal.querySelector('img').src = content.url;
postModal.querySelector('.likes-count').textContent = content.likes;
Expand All @@ -48,9 +46,12 @@ const openPostModal = (content) => {
const findPostContent = (evt, data) => {
const url = evt.target.closest('.picture').querySelector('img').src;
const photoId = Number(url.split('/').pop().split('.')[0]);
const res = data.find((photo) => photo.id === photoId);
postModal.classList.remove('hidden');
openPostModal(res);
const postData = data.find((photo) => photo.id === photoId);
openPostModal(postData);
};

document.addEventListener('keydown', (evt) => {
escKeypress(evt, closePostModal);
});

export {findPostContent};
8 changes: 7 additions & 1 deletion js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ const createRandomId = (min, max) => {
};
};

export {createRandomId, getRandomInteger};
const escKeypress = (evt, fn) => {
if (evt.key === 'Escape') {
fn();
}
};

export {createRandomId, getRandomInteger, escKeypress};

0 comments on commit d08f4e7

Please sign in to comment.