Skip to content

Commit 8d6847b

Browse files
committed
All reviews
1 parent e1d7907 commit 8d6847b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

cli-socks/src/components/Product.vue

Lines changed: 9 additions & 2 deletions
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>
@@ -50,6 +56,7 @@ import ProductReview from './ProductReview.vue';
5056
ProductReview
5157
}
5258
})
59+
5360
export default class Product extends Vue {
5461
@Prop({default: false}) private premium!: boolean;
5562
@@ -74,7 +81,7 @@ export default class Product extends Vue {
7481
if (!this.product.reviews.length) {
7582
return null;
7683
}
77-
return Math.round(this.product.reviews.reduce((a, c) => a + c, 0) / this.product.reviews.length);
84+
return Math.round(this.product.reviews.map(x => x.rating).reduce((a, c) => a + c, 0) / this.product.reviews.length);
7885
}
7986
8087
addToCart() {
@@ -85,7 +92,7 @@ export default class Product extends Vue {
8592
8693
addReview(review: any) {
8794
const reviews = this.product.reviews as any;
88-
reviews.push(review.rating);
95+
reviews.push(review);
8996
}
9097
}
9198
</script>

0 commit comments

Comments
 (0)