|
| 1 | +import React, { Component, PropTypes } from 'react'; |
| 2 | +import { connect } from 'react-redux'; |
| 3 | +import { |
| 4 | + addProduct, |
| 5 | + removeProduct, |
| 6 | + selectProduct, |
| 7 | + increaseProductQty |
| 8 | +} from '../actions'; |
| 9 | +import ProductList from '../components/ProductList'; |
| 10 | +import PurchaseButton from '../components/PurchaseButton'; |
| 11 | +import AccountBar from '../components/AccountBar'; |
| 12 | + |
| 13 | + |
| 14 | +class App extends Component { |
| 15 | + componentDidMount() { |
| 16 | + } |
| 17 | + |
| 18 | + componentWillReceiveProps(nextProps) { |
| 19 | + } |
| 20 | + |
| 21 | + addRandomProduct() { |
| 22 | + var eans = [ |
| 23 | + '7310500088853', |
| 24 | + '7340083438684', |
| 25 | + '7611612221351', |
| 26 | + '7310500114934', |
| 27 | + '7310070765840', |
| 28 | + '7315360010754', |
| 29 | + '7622300342753' |
| 30 | + ]; |
| 31 | + |
| 32 | + var randomIndex = Math.floor(Math.random() * eans.length); |
| 33 | + this.props.dispatch(addProduct(eans[randomIndex])); |
| 34 | + } |
| 35 | + |
| 36 | + render() { |
| 37 | + const { dispatch, products } = this.props; |
| 38 | + return ( |
| 39 | + <div id="container"> |
| 40 | + <ProductList products={products} |
| 41 | + onSelect={(ean) => dispatch(selectProduct(ean))} /> |
| 42 | + <span id="trash" className="button"></span> |
| 43 | + <div id="sidebar"> |
| 44 | + <AccountBar name="Krzysztof" balance="0" /> |
| 45 | + <div id="menubox"></div> |
| 46 | + <PurchaseButton products={products} /> |
| 47 | + </div> |
| 48 | + <div id="edit"> |
| 49 | + <span className="button scroll up" onClick={(e) => this.addRandomProduct()}><i className="fa fa-chevron-up"></i></span> |
| 50 | + <div className="container"> |
| 51 | + <span className="button plus" |
| 52 | + onClick={(e) => dispatch(increaseProductQty(1))}> |
| 53 | + <i className="fa fa-plus"></i> |
| 54 | + </span> |
| 55 | + <span className="button minus" |
| 56 | + onClick={(e) => dispatch(increaseProductQty(-1))}> |
| 57 | + <i className="fa fa-minus"></i> |
| 58 | + </span> |
| 59 | + <span className="button trash" |
| 60 | + onClick={(e) => dispatch(removeProduct())}> |
| 61 | + <i className="fa fa-trash"></i> |
| 62 | + </span> |
| 63 | + </div> |
| 64 | + <span className="button scroll down"> |
| 65 | + <i className="fa fa-chevron-down"></i> |
| 66 | + </span> |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + ); |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +App.propTypes = { |
| 74 | + dispatch: PropTypes.func.isRequired |
| 75 | +}; |
| 76 | + |
| 77 | +function mapStateToProps(state) { |
| 78 | + const { products } = state; |
| 79 | + |
| 80 | + return { |
| 81 | + products |
| 82 | + }; |
| 83 | +} |
| 84 | + |
| 85 | +export default connect(mapStateToProps)(App); |
0 commit comments