Skip to content

Commit

Permalink
Merge pull request #61 from val92130/develop
Browse files Browse the repository at this point in the history
2.8.2
  • Loading branch information
Valentin Chatelain authored Oct 18, 2017
2 parents d1e2c41 + c9d2995 commit f325cf9
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 275 deletions.
2 changes: 1 addition & 1 deletion bot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Supreme Auto-Checkout bot",
"description": "Supreme Open-Source add to cart bot",
"version": "2.8.1",
"version": "2.8.2",
"background": {
"scripts": ["background.js"]
},
Expand Down
156 changes: 156 additions & 0 deletions bot/src/app/components/shops/supreme/ProductList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import Divider from 'material-ui/Divider';
import CircularProgress from 'material-ui/CircularProgress';
import { Card, CardMedia, CardText } from 'material-ui/Card';
import TextField from 'material-ui/TextField';
import Dialog from 'material-ui/Dialog';
import Layout from '../../../containers/Layout';
import addNotification from '../../../actions/notification';
import { addAtcProduct } from '../../../actions/atc';
import AtcCreateForm from './AtcCreateForm';
import FuzzyStringMatcher from '../../../utils/FuzzyStringMatcher';

class ProductList extends Component {
constructor(props) {
super(props);
this.state = {
selectedProduct: null,
modalOpen: false,
filter: '',
};
}

handleSubmit(data) {
this.props.addAtcProduct(data);
this.handleRequestClose();
}

handleClickProduct(product) {
if (this.props.onProductClick) {
this.props.onProductClick(product);
return;
}
this.setState({
modalOpen: true,
selectedProduct: product,
});
}

handleRequestClose() {
this.setState({
modalOpen: false,
selectedProduct: null,
});
}

productToAtc(product) {
if (!product) return {};
return {
name: product.name,
keywords: product.keywords,
category: product.category,
};
}

getProductCard(product, onTouchTap) {
const style = {
width: 200,
minWidth: 250,
flex: 1,
margin: 20,
};

const imgStyle = {};

if (product.soldOut) {
imgStyle.filter = 'grayscale(100%)';
}

return (
<Card style={style} onTouchTap={onTouchTap}>
<div style={{ textAlign: 'center' }}>
<p style={{ fontSize: '0.9em' }}>
{product.name}
{product.color && <p>{product.color}</p>}
</p>
<CardMedia>
<img style={imgStyle} src={product.imageUrl} alt={product.name} />
</CardMedia>
<CardText>
{product.price && <p>Est price: {product.price}</p>}
</CardText>
</div>
<Divider />
</Card>
);
}

render() {
const products = this.props.products;
if (!products) {
return (
<Layout>
<div style={{ textAlign: 'center' }}>
<p>Loading...</p>
<CircularProgress />
</div>
</Layout>
);
}
let allProducts = [...products];
if (this.state.filter) {
const fuse = new FuzzyStringMatcher(allProducts, { key: 'name' });
allProducts = fuse.search(this.state.filter);
}
allProducts = allProducts.sort((a, b) => a.soldOut - b.soldOut);
const cards = allProducts.map(x => this.getProductCard(x, () => this.handleClickProduct(x)));
const style = {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-evenly',
flexWrap: 'wrap',
cursor: 'pointer',
};
return (
<Layout>
<Dialog
title="Buy now"
onRequestClose={() => this.handleRequestClose()}
open={this.state.modalOpen}
autoScrollBodyContent
>
<AtcCreateForm onRequestClose={() => this.handleRequestClose()} onSubmit={data => this.handleSubmit(data)} initialValues={this.productToAtc(this.state.selectedProduct)} />
</Dialog>
<div style={{ textAlign: 'center' }}>
{this.props.title || <p>Click on a product to add to AutoCop</p>}
</div>
<div style={{ textAlign: 'center' }}>
<TextField
hintText="filter..."
floatingLabelText="Filter"
onChange={(e, val) => this.setState({ filter: val })}
/>
</div>
<div style={style}>
{cards}
</div>
</Layout>
);
}
}

ProductList.propTypes = {
products: PropTypes.arrayOf(PropTypes.object),
onProductClick: PropTypes.func,
title: PropTypes.string,
};

function mapDispatchToProps(dispatch) {
return {
addAtcProduct: data => dispatch(addAtcProduct(data)),
notify: msg => dispatch(addNotification(msg)),
};
}

export default connect(undefined, mapDispatchToProps)(ProductList);
116 changes: 3 additions & 113 deletions bot/src/app/components/shops/supreme/pages/DropProducts.jsx
Original file line number Diff line number Diff line change
@@ -1,130 +1,20 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import Divider from 'material-ui/Divider';
import CircularProgress from 'material-ui/CircularProgress';
import { Card, CardMedia, CardText } from 'material-ui/Card';
import Dialog from 'material-ui/Dialog';
import Layout from '../../../../containers/Layout';
import DropsService from '../../../../../services/supreme/DropsService';
import addNotification from '../../../../actions/notification';
import { addAtcProduct } from '../../../../actions/atc';
import AtcCreateForm from '../AtcCreateForm';
import ProductList from '../ProductList';

class DropProducts extends Component {
export default class DropProducts extends Component {
constructor(props) {
super(props);
this.state = {
products: null,
selectedProduct: null,
modalOpen: false,
};

DropsService.fetchProducts(props.params.slug).then(products => this.setState({ products }));
}

handleSubmit(data) {
this.props.addAtcProduct(data);
this.handleRequestClose();
}

handleClickProduct(product) {
this.setState({
modalOpen: true,
selectedProduct: product,
});
}

handleRequestClose() {
this.setState({
modalOpen: false,
selectedProduct: null,
});
}

productToAtc(product) {
if (!product) return {};
return {
name: product.name,
keywords: product.keywords,
category: product.category,
};
}

getProductCard(product, onTouchTap) {
const style = {
width: 200,
minWidth: 250,
flex: 1,
margin: 20
};

const imgStyle = {
};

return (
<Card style={style} onTouchTap={onTouchTap}>
<div style={{ textAlign: 'center' }}>
<p style={{ fontSize: '0.9em' }}>
{product.name}
</p>
<CardMedia>
<img style={imgStyle} src={product.imageUrl} alt={product.name} />
</CardMedia>
<CardText>
{product.price && <p>Est price: {product.price}</p>}
</CardText>
</div>
<Divider />
</Card>
);
}

render() {
const products = this.state.products;
if (!products) {
return (
<Layout>
<div style={{ textAlign: 'center' }}>
<p>Loading...</p>
<CircularProgress />
</div>
</Layout>
);
}
const cards = products.map(x => this.getProductCard(x, () => this.handleClickProduct(x)));
const style = {
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-evenly',
flexWrap: 'wrap',
cursor: 'pointer',
};
return (
<Layout>
<Dialog
title="Buy now"
onRequestClose={() => this.handleRequestClose()}
open={this.state.modalOpen}
autoScrollBodyContent
>
<AtcCreateForm onRequestClose={() => this.handleRequestClose()} onSubmit={data => this.handleSubmit(data)} initialValues={this.productToAtc(this.state.selectedProduct)} />
</Dialog>
<div style={{ textAlign: 'center' }}>
<p>Click on a product to add to AutoCop</p>
</div>
<div style={style}>
{cards}
</div>
</Layout>
<ProductList products={this.state.products} />
);
}
}

function mapDispatchToProps(dispatch) {
return {
addAtcProduct: data => dispatch(addAtcProduct(data)),
notify: msg => dispatch(addNotification(msg)),
};
}

export default connect(undefined, mapDispatchToProps)(DropProducts);
Loading

0 comments on commit f325cf9

Please sign in to comment.