-
-

-
-
-
15 reviews
-
- {stars}
-
+ handleClick(e) {
+ e.preventDefault();
+ this.setState({
+ visible: !this.state.visible
+ });
+ }
+
+ render() {
+ const { name, description, rating, imgUrl, reviews } = this.props.product;
+
+ const stars = [];
+ const emptyStars = [];
+ for (let i = 0; i < rating; i++) {
+ stars.push(
);
+ }
+ for (let j = 0; j < 5 - rating; j++) {
+ emptyStars.push(
);
+ }
+
+ let reviewText = (reviews.length > 1) ? `${reviews.length} reviews` : `${reviews.length} review`;
+ return (
+
+
+

+
+
+
+
-
-
- );
+ );
+ }
}
+
export default ProductDetail;
diff --git a/src/components/Reviews.js b/src/components/Reviews.js
new file mode 100644
index 0000000..a6c6d41
--- /dev/null
+++ b/src/components/Reviews.js
@@ -0,0 +1,31 @@
+import React, { Component } from "react";
+
+class Reviews extends Component {
+
+ constructor() {
+ super();
+ }
+
+ render() {
+ const { reviews } = this.props.product;
+ let reviewListItems = "";
+
+ if (this.props.visible) {
+ reviewListItems = reviews.map((review, index) => {
+ return
{review.description};
+ });
+ } else {
+ reviewListItems = "";
+ }
+
+ return (
+
+
+ {reviewListItems}
+
+
+ );
+ }
+}
+
+export default Reviews;
diff --git a/src/state.js b/src/state.js
index badf378..cf3b41f 100644
--- a/src/state.js
+++ b/src/state.js
@@ -4,7 +4,7 @@ export default {
"id": 1,
"name": "Body Luxuries Sweet Lavender Hand Sanitizer",
"description": "Psychotropic drugs, not elsewhere classified",
- "reviews": 46,
+ //"reviews": 46,
"rating": 2,
"imgUrl": "http://dummyimage.com/136x167.bmp/cc0000/ffffff",
"price": "$95.11",
@@ -44,7 +44,7 @@ export default {
"id": 2,
"name": "Topiramate",
"description": "Injury of ulnar nerve at forearm level, left arm, sequela",
- "reviews": 2,
+ //"reviews": 2,
"rating": 2,
"imgUrl": "http://dummyimage.com/125x134.jpg/cc0000/ffffff",
"price": "$37.09",
@@ -70,7 +70,7 @@ export default {
"id": 3,
"name": "Almond",
"description": "Other disorders of continuity of bone, unsp tibia and fibula",
- "reviews": 27,
+ //"reviews": 27,
"rating": 5,
"imgUrl": "http://dummyimage.com/149x190.jpg/dddddd/000000",
"price": "$51.83",
@@ -90,7 +90,7 @@ export default {
"id": 4,
"name": "VYTORIN",
"description": "Orchard as the place of occurrence of the external cause",
- "reviews": 60,
+ //"reviews": 60,
"rating": 3,
"imgUrl": "http://dummyimage.com/162x153.jpg/cc0000/ffffff",
"price": "$86.93",
@@ -110,7 +110,7 @@ export default {
"id": 5,
"name": "Decolorized Iodine",
"description": "Injury",
- "reviews": 20,
+ //"reviews": 20,
"rating": 1,
"imgUrl": "http://dummyimage.com/120x245.jpg/cc0000/ffffff",
"price": "$70.10",
@@ -130,7 +130,7 @@ export default {
"id": 6,
"name": "Fresh Sugar Honey Tinted Lip Treatment SPF15",
"description": "Unspecified open wound ",
- "reviews": 79,
+ //"reviews": 79,
"rating": 3,
"imgUrl": "http://dummyimage.com/211x227.bmp/5fa2dd/ffffff",
"price": "$39.25",
@@ -150,7 +150,7 @@ export default {
"id": 7,
"name": "LBel",
"description": "Toxic effect of 2-Propanol, intentional self-harm, init",
- "reviews": 76,
+ //"reviews": 76,
"rating": 3,
"imgUrl": "http://dummyimage.com/212x144.jpg/ff4444/ffffff",
"price": "$99.91",
@@ -170,7 +170,7 @@ export default {
"id": 8,
"name": "Cholestyramine",
"description": "Laceration without foreign body of trachea, sequela",
- "reviews": 74,
+ //"reviews": 74,
"rating": 3,
"imgUrl": "http://dummyimage.com/204x175.jpg/5fa2dd/ffffff",
"price": "$67.17",
@@ -190,7 +190,7 @@ export default {
"id": 9,
"name": "Risperidone",
"description": "Poisn by cephalospor/oth beta-lactm antibiot, undet, sequela",
- "reviews": 9,
+ //"reviews": 9,
"rating": 1,
"imgUrl": "http://dummyimage.com/212x108.bmp/cc0000/ffffff",
"price": "$96.84",
@@ -210,7 +210,7 @@ export default {
"id": 10,
"name": "MAC",
"description": "Other Gram-negative sepsis",
- "reviews": 45,
+ //"reviews": 45,
"rating": 2,
"imgUrl": "http://dummyimage.com/189x109.png/cc0000/ffffff",
"price": "$74.37",