Skip to content

Commit 757e720

Browse files
authored
Merge pull request #21 from itenium-be/feature/3B-all-reviews
All reviews
2 parents e3390f7 + 8d6847b commit 757e720

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Diff for: cli-socks/src/components/Product.vue

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
<i v-for="i in averageReviewScore" class="fa fa-star" :key="i"></i>
1212
</h1>
1313

14+
<div>All reviews:</div>
15+
<div v-for="j in product.reviews" :key="j.name+j.rating">
16+
<label>{{ j.name}}: </label>
17+
<i v-for="k in j.rating" class="fa fa-star" :key="k"></i>
18+
</div>
19+
1420
<div>
1521
<p v-if="product.inventory > 10">In Stock</p>
1622
<p v-else-if="product.inventory">Almost sold out</p>
@@ -58,6 +64,7 @@ import ProductReview from './ProductReview.vue';
5864
ProductReview
5965
}
6066
})
67+
6168
export default class Product extends Vue {
6269
@Prop({default: false}) private premium!: boolean;
6370
@Prop() private cartLength: number;
@@ -84,7 +91,7 @@ export default class Product extends Vue {
8491
if (!this.product.reviews.length) {
8592
return null;
8693
}
87-
return Math.round(this.product.reviews.reduce((a, c) => a + c, 0) / this.product.reviews.length);
94+
return Math.round(this.product.reviews.map(x => x.rating).reduce((a, c) => a + c, 0) / this.product.reviews.length);
8895
}
8996
9097
get title() {
@@ -105,7 +112,7 @@ export default class Product extends Vue {
105112
106113
addReview(review: any) {
107114
const reviews = this.product.reviews as any;
108-
reviews.push(review.rating);
115+
reviews.push(review);
109116
}
110117
}
111118
</script>

0 commit comments

Comments
 (0)