diff --git a/public/css/shop-homepage.css b/public/css/shop-homepage.css index b498194..b8144a2 100755 --- a/public/css/shop-homepage.css +++ b/public/css/shop-homepage.css @@ -51,4 +51,4 @@ body { footer { margin: 50px 0; -} \ No newline at end of file +} diff --git a/src/components/ProductDetail.js b/src/components/ProductDetail.js index 885919a..f17397a 100644 --- a/src/components/ProductDetail.js +++ b/src/components/ProductDetail.js @@ -1,7 +1,8 @@ import React from "react"; +import Reviews from "./Reviews.js"; function ProductDetail(props) { - const {name,description,rating,imgUrl} = props.product; + const {name,description,rating,imgUrl, reviews} = props.product; const stars = []; for (let i = 0; i < rating; i++) { stars.push(); @@ -14,14 +15,18 @@ function ProductDetail(props) {

{name}

-

{description} +

{description}

-
-

15 reviews

-

- {stars} +

+

+ {stars} +

+

+ +

+
diff --git a/src/components/Reviews.js b/src/components/Reviews.js new file mode 100644 index 0000000..7ae16e5 --- /dev/null +++ b/src/components/Reviews.js @@ -0,0 +1,61 @@ +import React from "react"; + +class Reviews extends React.Component { + constructor(props) { + super(); + this.state = { + visible: false, + }; + + } + render() { + function fillStars(value) { + var arr = []; + for (var i = 0; i < value; i++) { + arr.push( < span className = "glyphicon glyphicon-star" > < /span>) + } + return arr; + }; + let reviewState = this.props.products; + let reviewDiv = ""; + let reviewTag; + if (reviewState.length > 1) { + reviewTag = "Reviews"; + } else { + reviewTag = "Review" + } + + + if (this.state.visible) { + reviewDiv = reviewState.map(function(type, index) { + return ( +
+ +
+

{type.description}

+

{fillStars(type.rating)}

+ +
+ ); + }) + } else { + reviewDiv = ""; + } + + return ( +
+ { + this.setState({ + visible: !this.state.visible + }); + } + } > {reviewTag} < /a> + {reviewDiv} +
+ ); + + } + } + + + export default Reviews;