import React from 'react'; import PropTypes from 'prop-types'; import { withStyles } from '@material-ui/core/styles'; import ViewList from '@material-ui/icons/ViewList'; import GridOn from '@material-ui/icons/GridOn'; import { Grid, Typography, Button } from '@material-ui/core'; import ProductCard from '../CardPaper/ProductCard'; import ProductDetail from './ProductDetail'; const styles = theme => ({ result: { margin: theme.spacing(1) }, option: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 10 }, button: { fontSize: 12, '& svg': { marginRight: 10 } }, appBar: { position: 'relative', }, flex: { flex: 1, }, }); class ProductGallery extends React.Component { state = { listView: false, open: false, } handleDetailOpen = (product) => { this.setState({ open: true }); this.props.showDetail(product); }; handleClose = () => { this.setState({ open: false }); }; handleSwitchView = () => { this.setState({ listView: !this.state.listView }); } render() { const { classes } = this.props; const { listView, open } = this.state; const { dataProduct, handleAddToCart, productIndex, keyword, } = this.props; const getTotalResult = dataArray => { let totalResult = 0; for (let i = 0; i < dataArray.size; i += 1) { if (dataArray.getIn([i, 'name']) === undefined) { return false; } if (dataArray.getIn([i, 'name']).toLowerCase().indexOf(keyword) !== -1) { totalResult += 1; } } return totalResult; }; return (
{getTotalResult(dataProduct)} {' '} Results
{ dataProduct.map((product, index) => { if (product.get('name').toLowerCase().indexOf(keyword) === -1) { return false; } const itemAttr = { id: product.get('id'), name: product.get('name'), thumbnail: product.get('thumbnail'), price: product.get('price'), quantity: 1 }; return ( this.handleDetailOpen(product)} addToCart={() => handleAddToCart(itemAttr)} /> ); }) }
); } } ProductGallery.propTypes = { classes: PropTypes.object.isRequired, dataProduct: PropTypes.object.isRequired, handleAddToCart: PropTypes.func.isRequired, showDetail: PropTypes.func.isRequired, productIndex: PropTypes.number.isRequired, keyword: PropTypes.string.isRequired, }; export default withStyles(styles)(ProductGallery);