diff --git a/astro/src/components/web/Reviews.astro b/astro/src/components/web/Reviews.astro new file mode 100644 index 0000000..6d22091 --- /dev/null +++ b/astro/src/components/web/Reviews.astro @@ -0,0 +1,50 @@ +--- +import StarRating from './subcomponents/StarRating.astro'; + +interface Props { + reviews: ReviewListComponent; +} + +const reviews = Astro.props.reviews; + +let totalStars: number = 0; +const totalReviews: number = reviews.reviews.length; + +reviews.reviews.forEach((review) => { + totalStars = totalStars + review.stars; +}); + +const averageStars = Math.round((totalStars / totalReviews) * 10) / 10; +const reviewsToShow = reviews.reviews.slice(0, 5); +--- + +
{averageStars} stars out of {totalReviews} {totalReviews === 1 ? "review" : "reviews"}.
+