Skip to content

Commit

Permalink
generate-card__fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirror45 committed Feb 1, 2024
1 parent 5d251c7 commit 21756af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
4 changes: 2 additions & 2 deletions js/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const activateFilters = () => {
};

const forms = ['.ad-form', '.map__filters'].map((selector) => {
formElement.document.querySelector(`${selector}`);
const formElements = document.querySelector(`${selector}`);
//Возвращаем новый объект: каждой формы, все поля форм, и класс disabled формы
return {
formElement,
partElements: formElement.querySelectorAll('fieldset, select'),
partElements: formElements.querySelectorAll('fieldset, select'),
disabledClass: `${selector}--disabled`
};
});
Expand Down
21 changes: 5 additions & 16 deletions js/generate-card.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fillElement } from './util.js';
import { fillElement, getGuestsNumber, getRoomsNumber, } from './util.js';

const cardTemplateElement = document.querySelector('#card').content.querySelector('.popup');

Expand All @@ -15,32 +15,21 @@ const generateCard = (data) => {
// Тип жилья
cardElement.querySelector('.popup__type').textContent = offer.type;
// Количество комнат
cardElement.querySelector('.popup__text--capacity').textContent = `${offer.rooms} комнаты для ${offer.guests} гостей`;
cardElement.querySelector('.popup__text--capacity').textContent = `${getRoomsNumber(offer.rooms)} для ${getGuestsNumber(offer.guests)}`;
// Время заезда и выезда
cardElement.querySelector(
'.popup__text--time'
).textContent = `Заезд после ${offer.checkin}, выезд до ${offer.checkout}`;
cardElement.querySelector('.popup__text--time').textContent = `Заезд после ${offer.checkin}, выезд до ${offer.checkout}`;
// Доступные удобства
const featuresElement = cardElement.querySelector('.popup__features');
fillElement(
featuresElement,
offer.features,
(feature) => `<li class="popup__feature popup__feature--${feature}"></li>`
);
fillElement(featuresElement, offer.features, (feature) => `<li class="popup__feature popup__feature--${feature}"></li>`);
// Описание объявления
cardElement.querySelector('.popup__description').textContent = offer.description;
// Фотографии объявления
const photoElement = cardElement.querySelector('.popup__photos');
fillElement(
photoElement,
offer.photos,
(photos) => `<img src="${photos}" class="popup__photo" width="45" height="40" alt="Фотография жилья" />`
);
fillElement(photoElement, offer.photos, (photos) => `<img src="${photos}" class="popup__photo" width="45" height="40" alt="Фотографии жилья" />`);
// Аватар пользователя
const avatarUserElement = cardElement.querySelector('.popup__avatar');
avatarUserElement.src = author.avatar;

//возвращаем заполненую карточку
return cardElement;
};

Expand Down
20 changes: 20 additions & 0 deletions js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ const fillElement = (
}
};

const getGuestsNumber = (guests) => {

Check failure on line 48 in js/util.js

View workflow job for this annotation

GitHub Actions / Check

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return guests % 10 === 1 && guests !== 11 ? `${guests} гостя` : `${guests} гостей`;
};

const getRoomsNumber = (rooms) => {
const reminder = rooms % 10;
if ((rooms >= 5 && rooms <= 20) || rooms === 0) {
return `${rooms} комнат`;
}
if (reminder === 1) {
return `${rooms} комната`;
}
if (reminder > 1 && reminder < 5) {
return `${rooms} комнаты`;
}
return `${rooms} комнат`;
};

const showAlert = (message) => {
const alertContainer = document.createElement('div');
alertContainer.style.zIndex = '100';
Expand Down Expand Up @@ -83,6 +101,8 @@ export {
getFixedNumber,
shufflArray,
fillElement,
getGuestsNumber,
getRoomsNumber,
showAlert,
debounce
};

0 comments on commit 21756af

Please sign in to comment.