From edda0b3613db6d65c6a4e6cd2f0cfb4ab57f8ca2 Mon Sep 17 00:00:00 2001 From: ASTIK Date: Thu, 25 Apr 2024 00:40:38 +0200 Subject: [PATCH] Refactor reviewsSlideHTML() and loadReviews() functions --- src/js/modules/dataLoaders/loadReviews.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/js/modules/dataLoaders/loadReviews.js b/src/js/modules/dataLoaders/loadReviews.js index 65e5ee9..5d5c046 100644 --- a/src/js/modules/dataLoaders/loadReviews.js +++ b/src/js/modules/dataLoaders/loadReviews.js @@ -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 : @@ -23,7 +28,7 @@ function reviewSlideHTML (avatar, {name, grade, text, date, link, linkText}) { return `
- ${avatar} + ${avatarElem}
${name}

${grade}/10 @@ -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) ); });