From c3c32e6794ad2d52ec56a04313c5b1ca09d4c6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20R=C3=B8skaft?= <haakoero@stud.ntnu.no> Date: Fri, 6 May 2022 15:15:03 +0200 Subject: [PATCH] Fixed so rating displayes on user item card --- src/components/BaseComponents/RatingModal.vue | 2 -- src/components/RentingComponents/ItemInfo.vue | 20 +++++++++++++++++-- .../UserListItemCard.vue | 12 ++--------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/components/BaseComponents/RatingModal.vue b/src/components/BaseComponents/RatingModal.vue index 1b09b8f..e65e9a4 100644 --- a/src/components/BaseComponents/RatingModal.vue +++ b/src/components/BaseComponents/RatingModal.vue @@ -189,8 +189,6 @@ export default { const postResponse = await postNewRating(ratingInfo); - console.log("posted: " + postResponse); - this.$router.push("/"); }, }, diff --git a/src/components/RentingComponents/ItemInfo.vue b/src/components/RentingComponents/ItemInfo.vue index beee721..b6fc63b 100644 --- a/src/components/RentingComponents/ItemInfo.vue +++ b/src/components/RentingComponents/ItemInfo.vue @@ -51,10 +51,11 @@ </p> </div> </div> - <div class="mt-2"> + <div class="mt-2" v-if="userForId"> <UserListItemCard :buttons="['chat']" :user="userForId" + :rating="rating" ></UserListItemCard> </div> <div class="mt-4"> @@ -140,6 +141,7 @@ export default { dateMessage: "Venligst velg dato for leieperioden", allowForRent: false, nonAvailableTimes: [], + rating: 0, }; }, components: { @@ -219,11 +221,25 @@ export default { amountOfDays = amountOfDays / 86400000; this.totPrice = this.item.pricePerDay * amountOfDays; }, + async getUserRating() { + let maybeRating = await UserService.getUserRatingAverage( + this.userForId.userId + ); + if (isNaN(maybeRating)) { + this.rating = NaN; + } + else { + this.rating = maybeRating; + if (this.rating > 5) this.rating = 5; + else if (this.rating < 1) this.rating = 1; + } + }, }, - async beforeMount() { + async created() { await this.getItemPictures(); await this.getItem(); await this.getUser(this.item.userID); + await this.getUserRating(); await this.getAvailableTimesForListing(); }, }; diff --git a/src/components/UserProfileComponents/UserListItemCard.vue b/src/components/UserProfileComponents/UserListItemCard.vue index a39ae00..012ba73 100644 --- a/src/components/UserProfileComponents/UserListItemCard.vue +++ b/src/components/UserProfileComponents/UserListItemCard.vue @@ -62,7 +62,6 @@ <script> import RatingComponent from "@/components/UserProfileComponents/RatingComponents/Rating.vue"; import IconButton from "@/components/BaseComponents/IconButton.vue"; -import UserService from "@/services/user.service"; import CommunityAdminService from "@/services/community-admin.service"; import { @@ -76,7 +75,6 @@ export default { name: "UserListItem", data() { return { - rating: -1.0, communityID: -1, profileImage: { src: require("../../assets/defaultUserProfileImage.jpg"), @@ -94,6 +92,7 @@ export default { props: { user: Object, buttons: Array, + rating: Number, }, computed: { getProfilePicture() { @@ -131,14 +130,7 @@ export default { ); }, }, - async beforeMount() { - 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; + async beforeMounted() { this.communityID = this.$route.params.communityID; }, }; -- GitLab