diff --git a/README.md b/README.md index 258a878..dbca118 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,21 @@ #### Setup +DONE Fork, clone, run yarn install, yarn start, pull request #### Do +DONE * Add a new class component for Reviews +DONE * Make sure to use extends and super +DONE * Import and use this component in ProductDetail +DONE * This component will take a product from props +DONE * It will show the number of reviews followed by "review" or "reviews" depending on if there is one or more reviews - * It will create a list of the reviews description which will inititally be hidden + DONE + * It will create a list of the reviews description which will initially be hidden + DONE * When the word "review" is clicked show the reviews - * When clicked again, hide the reviews \ No newline at end of file + DONE + * When clicked again, hide the reviews diff --git a/src/App.js b/src/App.js index 8dfa97f..d37bf15 100644 --- a/src/App.js +++ b/src/App.js @@ -8,7 +8,7 @@ import Carousel from './components/Carousel'; function App (props) { var products = props.state.products.map(function(prod){ - return ; + return ; }); return (
diff --git a/src/components/ProductDetail.js b/src/components/ProductDetail.js index 885919a..c22c9e3 100644 --- a/src/components/ProductDetail.js +++ b/src/components/ProductDetail.js @@ -1,10 +1,12 @@ import React from "react"; +import Reviews from "./Reviews" 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(); + stars.push(); + console.log("what is this?",props); } return ( @@ -14,11 +16,12 @@ function ProductDetail(props) {

{name}

-

{description} +

{description}

-

15 reviews

+

+

{stars}

diff --git a/src/components/Reviews.js b/src/components/Reviews.js new file mode 100644 index 0000000..f504a99 --- /dev/null +++ b/src/components/Reviews.js @@ -0,0 +1,43 @@ +import React from "react"; + +class Reviews extends React.Component{ + constructor (props) { + super(props); + this.state = { + visible: false, + }; + this.handleReviewClick = this.handleReviewClick.bind(this); + } + + handleReviewClick() { + this.setState(function(prevState) { + return { + visible: !prevState.visible + } + }); + } + + render() { + let reviews = this.props.product; + let numOfReviews = reviews.length; + + const reviewDiv = reviews.map((review) => { + if(this.state.visible) { + return ( +
+

{review.description} {review.rating}

+
+ ) + } + }); + + return ( +
+ {numOfReviews} review{numOfReviews <= 1 ? " " : "s" } +
{reviewDiv}
+
+ ); + } + } + +export default Reviews;