Skip to content

Commit

Permalink
Refactor reviewsSlideHTML() and loadReviews() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
astik-dev committed Apr 24, 2024
1 parent c1c2f86 commit edda0b3
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/js/modules/dataLoaders/loadReviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ const colors = {
orange: "#fab43c",
green: "#2CB67D",
}
const avatarAlt = `Avatar`;


function reviewSlideHTML (avatar, {name, grade, text, date, link, linkText}) {
function reviewsSlideHTML ({avatar, name, grade, text, date, link, linkText}) {

grade = +grade; // to number
const avatarElem = avatar == ""
? imageCreator.newImg("local", `reviews/user-avatar.svg`, avatarAlt)
: imageCreator.newWebpPic("external", `reviews/${avatar}.webp`, `reviews/${avatar}.jpeg`, avatarAlt);

grade = +grade; // to number

const gradeColor =
grade < 5 ? colors.red :
Expand All @@ -23,7 +28,7 @@ function reviewSlideHTML (avatar, {name, grade, text, date, link, linkText}) {
return `
<div class="reviews__slide swiper-slide">
<div class="reviews__slide-top">
${avatar}
${avatarElem}
<h5>${name}</h5>
<h4 class="reviews__slide-grade">
<span style="color: ${gradeColor};">${grade}/10</span>
Expand All @@ -48,15 +53,9 @@ export function loadReviews(reviews) {
removeEmptyItems(".reviews__slide_empty", reviewsSwiperWrapper);

reviews.forEach((review) => {

const alt = `Avatar`;
const avatar = review.avatar == ""
? imageCreator.newImg("local", `reviews/user-avatar.svg`, alt)
: imageCreator.newWebpPic("external", `reviews/${review.avatar}.webp`, `reviews/${review.avatar}.jpeg`, alt);

reviewsSwiperWrapper.insertAdjacentHTML(
"beforeend",
reviewSlideHTML(avatar, review)
reviewsSlideHTML(review)
);
});

Expand Down

0 comments on commit edda0b3

Please sign in to comment.