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: 3 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import NavBar from './components/NavBar';
import Footer from './components/Footer';
import ProductDetail from './components/ProductDetail';
import Carousel from './components/Carousel';

function App (props) {

var products = props.state.products.map(function(prod){
return <ProductDetail product={prod} />;
});
console.log("Products:",products);

return (
<div className="App">
<NavBar />
Expand Down
7 changes: 4 additions & 3 deletions src/components/ProductDetail.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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(<span className="glyphicon glyphicon-star" />);
Expand All @@ -14,11 +15,11 @@ function ProductDetail(props) {
<div className="caption">
<h4><a href="#">{name}</a>
</h4>
<p>{description}
<p>{description}
</p>
</div>
<div className="ratings">
<p className="pull-right">15 reviews</p>
<Reviews numberOfReviews = {reviews}/>
<p>
{stars}
</p>
Expand Down
35 changes: 35 additions & 0 deletions src/components/Reviews.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { Component } from 'react';
//props passed to class component via "this.props"
class Reviews extends Component {
state = {showing: false};

render(){
let firstReview;
if (this.state.showing) {
firstReview = <div>{this.props.numberOfReviews[0].description}</div>;
} else {
firstReview = <div></div>;
}

return(
<div>
<button onClick={
()=>{
console.log("Showing?",this.state.showing);
if (this.state.showing === false){
let newShow = true;
this.setState({showing: newShow});
}else if (this.state.showing === true) {
let newShow = false;
this.setState({showing: newShow});
}
console.log("First Review:",this.props.numberOfReviews[0].description);
}
}>{this.props.numberOfReviews.length} Reviews</button>
{firstReview}
</div>
)
}
}

export default Reviews;
8 changes: 4 additions & 4 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default {
"price": "$95.11",
"category": "food",
"reviews": [{
"description": "architect revolutionary deliverables",
"description": "Aarchitect revolutionary deliverables",
"rating": 2
}, {
"description": "orchestrate dynamic schemas",
Expand Down Expand Up @@ -50,7 +50,7 @@ export default {
"price": "$37.09",
"category": "food",
"reviews": [{
"description": "architect revolutionary deliverables",
"description": "Barchitect revolutionary deliverables",
"rating": 2
}, {
"description": "orchestrate dynamic schemas",
Expand All @@ -76,7 +76,7 @@ export default {
"price": "$51.83",
"category": "food",
"reviews": [{
"description": "architect revolutionary deliverables",
"description": "Carchitect revolutionary deliverables",
"rating": 2
}, {
"description": "orchestrate dynamic schemas",
Expand Down Expand Up @@ -221,4 +221,4 @@ export default {
}
]
}]
}
}