diff --git a/src/components/ItemComponents/NewItemForm.vue b/src/components/ItemComponents/NewItemForm.vue index 4e5fff4a64e1b606296963dcbbaefbcd71838703..f75f49eaac9d194ca0b952dcf63eabbba8f5073a 100644 --- a/src/components/ItemComponents/NewItemForm.vue +++ b/src/components/ItemComponents/NewItemForm.vue @@ -216,7 +216,12 @@ <script> import useVuelidate from "@vuelidate/core"; import { parseUserFromToken } from "@/utils/token-utils"; -import {postNewItem, getMyGroups, postNewImageCommunity, PostImagesArrayToListing} from "@/utils/apiutil"; +import { + postNewItem, + getMyGroups, + postNewImageCommunity, + PostImagesArrayToListing, +} from "@/utils/apiutil"; import Button from "@/components/BaseComponents/ColoredButton"; import { @@ -366,7 +371,6 @@ export default { //Not sure if this will work that.item.imagesToSend.push(API_URL + "images/" + id); - }; fileReader.readAsArrayBuffer(image); }, diff --git a/src/components/UserProfileComponents/RatingComponents/Rating.vue b/src/components/UserProfileComponents/RatingComponents/Rating.vue index 1db98bfb010248d1cf3d554df1f946a6867e6dc9..6efa3b014f4c175b7af950ddb36119a7029f60f9 100644 --- a/src/components/UserProfileComponents/RatingComponents/Rating.vue +++ b/src/components/UserProfileComponents/RatingComponents/Rating.vue @@ -1,5 +1,17 @@ <template> - <ul v-if="rating != -1" class="flex justify-center"> + <ul v-if="isNaN(rating)" class="flex justify-center"> + <li> + <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"> + {{ ratingType }}: + </p> + </li> + <li> + <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"> + Ingen vurderinger + </p> + </li> + </ul> + <ul v-else class="flex justify-center"> <li> <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"> {{ ratingType }}: @@ -18,21 +30,10 @@ </svg> </li> <li> - <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"> + <!-- Trenger vi å vise i tekst når vi har stjerner? --> + <!-- <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"> {{ rating }} out of 5 - </p> - </li> - </ul> - <ul v-else class="flex justify-center"> - <li> - <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"> - {{ ratingType }}: - </p> - </li> - <li> - <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400"> - Ingen vurderinger - </p> + </p> --> </li> </ul> </template> diff --git a/src/components/UserProfileComponents/UserListItemCard.vue b/src/components/UserProfileComponents/UserListItemCard.vue index 1d6bd9f2472695c6427f96026a8b212ab9d130a9..4bbbafe66dd646da32abd101818231ff7ffd807a 100644 --- a/src/components/UserProfileComponents/UserListItemCard.vue +++ b/src/components/UserProfileComponents/UserListItemCard.vue @@ -18,7 +18,7 @@ <!-- User rating --> <div class="hidden md:block flex-auto"> - <RatingComponent :rating="rating" :ratingType="'Gjennomsnitts rating'" /> + <RatingComponent :rating="rating" :ratingType="'Vurderinger'" /> </div> <!-- Buttons --> @@ -132,7 +132,13 @@ export default { }, }, async created() { - this.rating = await UserService.getUserRatingAverage(this.user.userId); + const maybeRating = await UserService.getUserRatingAverage( + this.user.userId + ); + if (isNaN(maybeRating)) this.rating = NaN; + else this.rating = maybeRating; + if (this.rating > 5) this.rating = 5; + if (this.rating < 1) this.rating = 1; this.communityID = this.$route.params.communityID; }, }; diff --git a/src/utils/apiutil.js b/src/utils/apiutil.js index 94221032becec82269c8a9de7473bdb4fb4831c4..f72cdd3450d60653621fce6966ef4ccd3231b263 100644 --- a/src/utils/apiutil.js +++ b/src/utils/apiutil.js @@ -343,14 +343,14 @@ export function postNewImageCommunity(image) { export function PostImagesArrayToListing(imagesArray) { return axios - .post(API_URL + "listing/pictures", imagesArray, { - headers: tokenHeader(), - }) - .then((response) => { - return response; - }) - .catch((error) => { - console.error(error.response); - return error; - }); + .post(API_URL + "listing/pictures", imagesArray, { + headers: tokenHeader(), + }) + .then((response) => { + return response; + }) + .catch((error) => { + console.error(error.response); + return error; + }); } diff --git a/tests/unit/component-tests/user-component-tests/__snapshots__/rating.spec.js.snap b/tests/unit/component-tests/user-component-tests/__snapshots__/rating.spec.js.snap index e7d04a61c2d249a8bda1825ed17ed7be65bcf319..f22076edecd3620957e0bbf9141873adfd3a6322 100644 --- a/tests/unit/component-tests/user-component-tests/__snapshots__/rating.spec.js.snap +++ b/tests/unit/component-tests/user-component-tests/__snapshots__/rating.spec.js.snap @@ -11,73 +11,11 @@ exports[`Rating component renders correctly 1`] = ` : </p> </li> - - <li> - <svg - class="w-5 h-5 text-gray-300 dark:text-gray-500" - fill="currentColor" - viewBox="0 0 20 20" - xmlns="http://www.w3.org/2000/svg" - > - <path - d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" - /> - </svg> - </li> - <li> - <svg - class="w-5 h-5 text-gray-300 dark:text-gray-500" - fill="currentColor" - viewBox="0 0 20 20" - xmlns="http://www.w3.org/2000/svg" - > - <path - d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" - /> - </svg> - </li> - <li> - <svg - class="w-5 h-5 text-gray-300 dark:text-gray-500" - fill="currentColor" - viewBox="0 0 20 20" - xmlns="http://www.w3.org/2000/svg" - > - <path - d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" - /> - </svg> - </li> - <li> - <svg - class="w-5 h-5 text-gray-300 dark:text-gray-500" - fill="currentColor" - viewBox="0 0 20 20" - xmlns="http://www.w3.org/2000/svg" - > - <path - d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" - /> - </svg> - </li> - <li> - <svg - class="w-5 h-5 text-gray-300 dark:text-gray-500" - fill="currentColor" - viewBox="0 0 20 20" - xmlns="http://www.w3.org/2000/svg" - > - <path - d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" - /> - </svg> - </li> - <li> <p class="ml-2 text-sm font-medium text-gray-500 dark:text-gray-400" > - out of 5 + Ingen vurderinger </p> </li> </ul>