Skip to content

Commit

Permalink
исправил функцию onShowMoreComments
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksimRozov committed Mar 12, 2024
1 parent 620d7dd commit 0949f1a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
1 change: 0 additions & 1 deletion js/create-thumbnails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const addPhotoThumbnailsUsers = () => {
pictureItem.addEventListener('click', (evt) =>{
evt.preventDefault();
onOpenBigPicture(element);

});

});
Expand Down
1 change: 0 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {addPhotoThumbnailsUsers} from './create-thumbnails';
import './showLargePicture';

addPhotoThumbnailsUsers();
28 changes: 13 additions & 15 deletions js/showLargePicture/createComments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {buttonShowMore, socialCommentsList, commentShownCount} from './elementVariables';
import {buttonShowMore, socialCommentsList, commentShownCount, socialCommentChild} from './elementVariables';
const LIMITED_DISPLAY_COMMENTS = 5;
let arrayComments = [];


const createComment = (comments) => {
Expand All @@ -20,30 +22,26 @@ const createComment = (comments) => {
return socialComment;
};

const onShowMoreComments = (element) =>{
let limit = 5;
const commentsList = element.splice(0, limit);
const socialCommentChild = socialCommentsList.children;
commentShownCount.textContent = socialCommentChild.length;
const onShowMoreComments = () =>{
const currentShowedComments = socialCommentsList.childElementCount;
const commentsCount = currentShowedComments + LIMITED_DISPLAY_COMMENTS;
const commentsLimited = arrayComments.length >= commentsCount ? commentsCount : arrayComments.length;
const commentsList = arrayComments.slice(currentShowedComments, commentsLimited);

commentsList.forEach((item) =>{
const commentElement = createComment(item);
socialCommentsList.append(commentElement);
commentShownCount.textContent = socialCommentChild.length;
});
buttonShowMore.addEventListener('click', () =>{
limit += 5;
onShowMoreComments(element);
});

};

const renderComments = (element, limit) => {
const minLimit = limit;
socialCommentsList.innerHTML = '';
onShowMoreComments(element,minLimit);

buttonShowMore.addEventListener('click', onShowMoreComments);

const renderComments = (element) => {
arrayComments = element;
socialCommentsList.innerHTML = '';
onShowMoreComments();
};


Expand Down
2 changes: 2 additions & 0 deletions js/showLargePicture/elementVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const commentShownCount = bigPictureBlock.querySelector('.social__comment
export const socialCaption = bigPictureBlock.querySelector('.social__caption');
export const socialCommentsList = bigPictureBlock.querySelector('.social__comments');
export const buttonShowMore = bigPictureBlock.querySelector('.social__comments-loader');
export const socialCommentChild = socialCommentsList.children;

7 changes: 4 additions & 3 deletions js/showLargePicture/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bigPictureBlock, bigPictureCancel, bigPictureImg, likesCount, commentTotalCount, socialCaption, socialCommentsList} from './elementVariables';
import { bigPictureBlock, bigPictureCancel, bigPictureImg, likesCount, commentTotalCount, socialCaption, socialCommentsList, buttonShowMore} from './elementVariables';
import {renderComments} from './createComments';


Expand All @@ -10,6 +10,8 @@ const toggleClass = (isOpened = true) =>{
const onCloseBigPicture = () => {
toggleClass(false);
socialCommentsList.innerHTML = '';
buttonShowMore.classList.remove('hidden');

bigPictureCancel.removeEventListener('click', onCloseBigPicture);
};

Expand All @@ -23,10 +25,9 @@ const addInformation = ({url, description, likes, comments}) =>{
};

const onOpenBigPicture = (element) => {
const limited = 5;
addInformation(element);
toggleClass();
renderComments(element.comments, limited);
renderComments(element.comments);

bigPictureCancel.addEventListener('click', onCloseBigPicture);
};
Expand Down

0 comments on commit 0949f1a

Please sign in to comment.