Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Fork, clone, run yarn install, yarn start, pull request

#### Do
* Add a new class component for Reviews
* Make sure to use extends and super
* Import and use this component in ProductDetail
* This component will take a product from props
* It will show the number of reviews followed by "review" or "reviews" depending on if there is one or more reviews
Add a new class component for Reviews
Make sure to use extends and super
Import and use this component in ProductDetail
This component will take a product from props
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
* When the word "review" is clicked show the reviews
* When clicked again, hide the reviews
3 changes: 2 additions & 1 deletion src/components/ProductDetail.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from "react";
import Reviews from "./Reviews"

function ProductDetail(props) {
const {name,description,rating,imgUrl} = props.product;
Expand All @@ -18,7 +19,7 @@ function ProductDetail(props) {
</p>
</div>
<div className="ratings">
<p className="pull-right">15 reviews</p>
<Reviews product={props.product}/>
<p>
{stars}
</p>
Expand Down
41 changes: 41 additions & 0 deletions src/components/Reviews.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';

class Reviews extends React.Component{
constructor(){
super();
this.state = {
hidden: true
}
}
//this component has a product sent in as prop

toggleHide() {
this.setState({hidden: !this.state.hidden});
}
render(){
// console.log(this.props.product.reviews);
let plural = "";
if (this.props.product.reviews.length > 1) {
plural = "s";
}
const reviewsDiv = this.props.product.reviews.map((review)=>{
return (
<div>
<p>Description: {review.description}</p>
<p>Rating: {review.rating}</p>
</div>
)
}
);
return (
<div>
<div className="pull-right" onClick={()=>{
this.toggleHide()
}}>{this.props.product.reviews.length} review{plural}</div>

{this.state.hidden ? <div /> : reviewsDiv }
</div>
)
}
}
export default Reviews;