1- import React from 'react' ;
1+ import React , { Component } from 'react' ;
22import { Link } from 'react-router-dom'
33import { connect } from 'react-redux'
4+ import CategoryProduct from './CategoryProduct'
45
56
6- const CategoryProducts = ( props ) => {
7+ class CategoryProducts extends Component {
8+ constructor ( props ) {
9+ super ( props ) ;
10+
11+ this . state = {
12+
13+ }
14+ }
15+
16+
717
8- // console.log("categoryProducts", props)
18+
19+ render ( ) {
20+
21+ // console.log("categoryProducts", props)
922 // console.log("category props", props.categories.categories)
1023
11- let productList = props . match ? props . categories . categories . filter ( category => category . id === props . match . params . id ) [ 0 ] : null
12- const CategoryId = props . match ? props . match . params . id [ 0 ] : null
24+ let productList = this . props . match ? this . props . categories . categories . filter ( category => category . id === this . props . match . params . id ) [ 0 ] : null
25+ const CategoryId = this . props . match ? this . props . match . params . id [ 0 ] : null
1326 const CategoryName = productList ? < li className = "category-name" > { productList . attributes . name } </ li > : null
1427
1528 // console.log("products", productList);
@@ -18,39 +31,90 @@ const CategoryProducts = (props) => {
1831 return a . subcategory_id - b . subcategory_id ;
1932 } )
2033 : null
21- // console.log("sortedProducts", sortedProducts)
34+ console . log ( "sortedProducts" , sortedProducts )
35+
2236
2337
24- let categoryProducts = sortedProducts ? sortedProducts . map ( product =>
25- < div key = { product . id } >
26- < Link to = { `/category/${ CategoryId } /products/${ product . id } ` } >
27- < li className = "products-image" > < img src = { product . image } alt = "product" > </ img > </ li >
28- < li className = "products-text" > { product . name } < br > </ br > </ li >
29- </ Link >
30- < li className = "products-price" > ${ product . price } </ li >
31- </ div >
32- )
38+ let categoryProducts = sortedProducts ? sortedProducts . map ( product => (
39+ < CategoryProduct
40+ key = { product . id }
41+ id = { product . id }
42+ image = { product . image }
43+ price = { product . price }
44+ name = { product . name }
45+ votes = { product . votes }
46+ description = { product . description }
47+ item_number = { product . item_number }
48+ />
49+ ) )
3350 : null
3451
3552
36- return (
37-
38- < div className = "products" >
39-
40- < h1 className = "products" > { CategoryName } </ h1 >
53+ return (
54+
4155 < div className = "products" >
42- { categoryProducts }
43-
44- </ div >
45- </ div >
46- )
56+ < h1 className = "products" > { CategoryName } </ h1 >
57+ < div className = "" >
58+ { categoryProducts }
59+
60+ </ div >
61+ </ div >
62+ )
63+
64+ }
4765}
48-
66+
4967const mapStateToProps = state => {
50- return {
51- categories : state . categoryReducer ,
52- subcategories : state . subcategoryReducer ,
53- } ;
68+ return {
69+ categories : state . categoryReducer ,
70+ subcategories : state . subcategoryReducer ,
71+ } ;
5472}
5573
56- export default connect ( mapStateToProps ) ( CategoryProducts ) ;
74+ export default connect ( mapStateToProps ) ( CategoryProducts ) ;
75+
76+
77+
78+
79+ // const CategoryProducts = (props) => {
80+
81+ // // console.log("categoryProducts", props)
82+ // // console.log("category props", props.categories.categories)
83+
84+ // let productList = props.match ? props.categories.categories.filter(category => category.id === props.match.params.id)[0] : null
85+ // const CategoryId = props.match ? props.match.params.id[0] : null
86+ // const CategoryName = productList ? <li className="category-name">{productList.attributes.name}</li> : null
87+
88+ // // console.log("products", productList);
89+
90+ // let sortedProducts = productList ? productList.attributes.products.sort(function(a,b){
91+ // return a.subcategory_id - b.subcategory_id;
92+ // })
93+ // : null
94+ // // console.log("sortedProducts", sortedProducts)
95+
96+
97+ // let categoryProducts = sortedProducts ? sortedProducts.map(product =>
98+ // <div key={product.id}>
99+ // <Link to={`/category/${CategoryId}/products/${product.id}` }>
100+ // <li className="products-image"> <img src={ product.image } alt="product" ></img></li>
101+ // <li className="products-text"> { product.name } <br></br></li>
102+ // </Link>
103+ // <li className="products-price"> ${ product.price }</li>
104+ // <button onClick={this.handleClick}>Vote</button>
105+ // <li>0</li>
106+ // </div>
107+ // )
108+ // : null
109+
110+
111+ // }
112+
113+ // const mapStateToProps = state => {
114+ // return {
115+ // categories: state.categoryReducer,
116+ // subcategories: state.subcategoryReducer,
117+ // };
118+ // }
119+
120+ // export default connect(mapStateToProps)(CategoryProducts);
0 commit comments