Skip to content

Commit

Permalink
fix: меняет сортировку на количество комментариев вместо лайков, доба…
Browse files Browse the repository at this point in the history
…вляет переменную с классом активного фильтра
  • Loading branch information
TatianaSenatorova committed Dec 15, 2024
1 parent 61d4b0f commit 48794c4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
7 changes: 4 additions & 3 deletions js/filters.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const filters = document.querySelector('.img-filters');
const filtersButtons = filters.querySelectorAll('.img-filters__button');
const ACTIVE_BUTTON_CLASS = 'img-filters__button--active';


const showFilters = () => filters.classList.remove('img-filters--inactive');

const setFilterClick = (cb) => {
filters.addEventListener('click', (evt) => {
if(evt.target.classList.contains('img-filters__button') && !evt.target.classList.contains('img-filters__button--active')) {
filtersButtons.forEach((button) => button.classList.remove('img-filters__button--active'));
if(evt.target.classList.contains('img-filters__button') && !evt.target.classList.contains(ACTIVE_BUTTON_CLASS)) {
filtersButtons.forEach((button) => button.classList.remove(ACTIVE_BUTTON_CLASS));
const currentFilter = evt.target;
currentFilter.classList.add('img-filters__button--active');
currentFilter.classList.add(ACTIVE_BUTTON_CLASS);
const dataFilterId = currentFilter.getAttribute('id');
cb(dataFilterId);
}
Expand Down
11 changes: 1 addition & 10 deletions js/render-photos.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ const createThumbnail = (photo) => {
return thumbnail;
};

const getPhotoLikes = (photo) => photo.likes;

const comparePhotos = (photoA, photoB) => {
const likesA = getPhotoLikes(photoA);
const likesB = getPhotoLikes(photoB);
return likesB - likesA;
};


const getPhotosToRender = (photos, filter) => {
let photosToRender = [];
let copyPhotos = photos.slice();
Expand All @@ -40,7 +31,7 @@ const getPhotosToRender = (photos, filter) => {
}
return photosToRender;
} else if (filter === 'filter-discussed') {
photosToRender = copyPhotos.sort(comparePhotos).slice(0, PHOTO_NUMBERS_DEFAULT);
photosToRender = copyPhotos.sort((a,b) => b.comments.length - a.comments.length).slice(0, PHOTO_NUMBERS_DEFAULT);
return photosToRender;
}
photosToRender = copyPhotos.slice(0, PHOTO_NUMBERS_DEFAULT);
Expand Down

0 comments on commit 48794c4

Please sign in to comment.