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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

#webstorm
.idea/
73 changes: 51 additions & 22 deletions src/components/ProductDetail.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,59 @@
import React from "react";
import Reviews from "./Reviews";

function ProductDetail(props) {
const {name,description,rating,imgUrl} = props.product;
const stars = [];
for (let i = 0; i < rating; i++) {
stars.push(<span className="glyphicon glyphicon-star" />);

class ProductDetail extends React.Component {
constructor(props) {
super(props);
this.state = {
visible: false
};
}

return (
<div className="col-sm-4 col-lg-4 col-md-4">
<div className="thumbnail">
<img style={{width: "320px",height: "150px"}} src={imgUrl} alt="" />
<div className="caption">
<h4><a href="#">{name}</a>
</h4>
<p>{description}
</p>
</div>
<div className="ratings">
<p className="pull-right">15 reviews</p>
<p>
{stars}
</p>
buttonClick = () => {
this.setState(prevState => ({
visible: !prevState.visible
}));
console.log(this.state.visible);
};

render() {

const {name, description, rating, imgUrl} = this.props.product;
const stars = [];
for (let i = 0; i < rating; i++) {
stars.push(<span className="glyphicon glyphicon-star"/>);
}
const reviewIt = this.props.product.reviews.map((r) => {
if (this.state.visible) {
return <Reviews review={r} />
}
return <span></span>;
});
return (
<div className="col-sm-4 col-lg-4 col-md-4">
<div className="thumbnail">
<img style={{width: "320px", height: "150px"}} src={imgUrl} alt=""/>
<div className="caption">
<h4><a href="#">{name}</a>
</h4>
<p>{description}
</p>
</div>
<div className="ratings">
<div className="pull-right">
<ol onClick={this.buttonClick}>
{this.props.product.reviews.length} reviewz {reviewIt}
</ol>
</div>
<p>
{stars}
</p>
</div>
</div>
</div>
</div>
);
);
}
}
// :)
export default ProductDetail;
15 changes: 15 additions & 0 deletions src/components/Reviews.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react";
import {Component} from "react";

class Reviews extends React.Component {
constructor(props) {
super(props);
}

render() {

return (<li>{this.props.review.description}</li>)
}
}

export default Reviews;