From 545b73a3301a0ef75be9f38a3ac4db200f0d276d Mon Sep 17 00:00:00 2001 From: "jannik.lange" Date: Wed, 7 Aug 2024 08:24:59 +0200 Subject: [PATCH 1/2] :bug: added computed rating with min-max limits --- src/components/Comment/MucComment.vue | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/components/Comment/MucComment.vue b/src/components/Comment/MucComment.vue index 72eb672a..a0fb9be9 100644 --- a/src/components/Comment/MucComment.vue +++ b/src/components/Comment/MucComment.vue @@ -126,17 +126,25 @@ const showDate = computed(() => { return !!slots["date"]; }); +/** + * Computes class for given variant + */ const commentClass = computed(() => { return props.variant === "slider" ? "m-comment--slider" : "m-comment--listing"; }); +/** + * Computes rating with min and max limits + */ +const computedRating = computed(() => Math.min(Math.max(props.rating, 0), MAX_STARS)) + /* * Converts the dot used on decimal numbers and converts it to a comma. */ const ratingWithDecimalComma = computed(() => { - return props.rating.toLocaleString(LOCALES.valueOf(), { + return computedRating.value.toLocaleString(LOCALES.valueOf(), { minimumFractionDigits: 1, }); }); @@ -145,14 +153,14 @@ const ratingWithDecimalComma = computed(() => { Calculates the amount of full, empty and half-stars to be displayed. */ const evaluateRating = computed(() => { - const decimalPart = +(props.rating % 1).toFixed(1); // ask Brendan Eich why "3.3 % 1 = 0.2999999999999998" and then come back + const decimalPart = +(computedRating.value % 1).toFixed(1); // ask Brendan Eich why "3.3 % 1 = 0.2999999999999998" and then come back - let fullStars = Math.min(Math.floor(props.rating), MAX_STARS); - let emptyStars = Math.floor(MAX_STARS - props.rating); + let fullStars = Math.min(Math.floor(computedRating.value), MAX_STARS); + let emptyStars = Math.floor(MAX_STARS - computedRating.value); let isHalfStar = false; // evaluating half-stars and if the rating is e.g. 3.9 an extra full star needs to be displayed - if (props.rating !== 0.0 && props.rating !== MAX_STARS) { + if (computedRating.value !== 0.0 && computedRating.value !== MAX_STARS) { if (decimalPart <= LOWER_THRESHOLD) emptyStars++; else if (decimalPart >= UPPER_THRESHOLD) fullStars++; else isHalfStar = true; From a50fe3eb258040b88af16f21b692f94dc05fe378 Mon Sep 17 00:00:00 2001 From: "jannik.lange" Date: Wed, 7 Aug 2024 08:30:12 +0200 Subject: [PATCH 2/2] :rotating_light: formated code #165 --- src/components/Comment/MucComment.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Comment/MucComment.vue b/src/components/Comment/MucComment.vue index a0fb9be9..46b81e2c 100644 --- a/src/components/Comment/MucComment.vue +++ b/src/components/Comment/MucComment.vue @@ -138,7 +138,9 @@ const commentClass = computed(() => { /** * Computes rating with min and max limits */ -const computedRating = computed(() => Math.min(Math.max(props.rating, 0), MAX_STARS)) +const computedRating = computed(() => + Math.min(Math.max(props.rating, 0), MAX_STARS) +); /* * Converts the dot used on decimal numbers and converts it to a comma.