Skip to content

Commit

Permalink
realized point 4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil888-m committed Dec 18, 2024
1 parent b18a680 commit 676597c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h2 class="img-upload__title visually-hidden">Загрузка фотограф
</fieldset>

<!-- Форма редактирования изображения -->
<div class="img-upload__overlay hidden">
<div class="img-upload__overlay hidden">
<div class="img-upload__wrapper">
<div class="img-upload__preview-container">

Expand Down
19 changes: 14 additions & 5 deletions js/big-picture-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const popupCancelElement = document.querySelector('.big-picture__cancel');
const commentsLoadBtn = bigPhotoPopup.querySelector('.comments-loader');

let currentComments = null;
let currentCommentsCount = 0;
let currentShownCommentsCount = 0;

function onEscapeKeydown(e) {
if (e.key === 'Escape') {
Expand All @@ -21,8 +21,8 @@ function onLoadBtnClick(e) {
}

function loadComments() {
if (currentComments.length > currentCommentsCount) {
currentComments.slice(currentCommentsCount, currentCommentsCount + COMMENTS_STEP).forEach((comment) => {
if (currentComments.length > currentShownCommentsCount) {
currentComments.slice(currentShownCommentsCount, currentShownCommentsCount + COMMENTS_STEP).forEach((comment) => {
const commEl = document.createElement('li');
commEl.className = 'social__comment';

Expand All @@ -40,16 +40,17 @@ function loadComments() {
commEl.append(imgEl);
commEl.append(pEl);
bigPhotoPopup.querySelector('.social__comments').append(commEl);
currentCommentsCount++;
currentShownCommentsCount++;
});

bigPhotoPopup.querySelector('.social__comment-shown-count').textContent = bigPhotoPopup.querySelectorAll('.social__comment').length;
checkShownCommentsCount();
}
}

function clearComments() {
bigPhotoPopup.querySelector('.social__comments').innerHTML = '';
currentCommentsCount = 0;
currentShownCommentsCount = 0;
}

function renderComments(comments) {
Expand Down Expand Up @@ -85,6 +86,14 @@ function openBigPhotoPopup(photoId) {
}
}

function checkShownCommentsCount() {
if (currentComments.length <= currentShownCommentsCount) {
hide(commentsLoadBtn);
} else {
show(commentsLoadBtn);
}
}

popupCancelElement.addEventListener('click', hidePhotoPopup);
commentsLoadBtn.addEventListener('click', onLoadBtnClick);
export { openBigPhotoPopup };

0 comments on commit 676597c

Please sign in to comment.