Created
January 6, 2019 21:07
-
-
Save Franckapik/3f44e04f014b340be339abffa7992a92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react'; | |
import slide from './store'; | |
import {view} from 'react-easy-state'; | |
class Cart extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
empty: true | |
}; | |
} | |
lessCart() { | |
var i = slide.cart.findIndex(x => x.nom == this); | |
if (slide.cart[i].qte > 1) { | |
slide.cart[i].qte--; | |
slide.somme(); | |
} else { | |
slide.cart.splice(i, 1); | |
slide.somme(); | |
} | |
} | |
plusCart() { | |
var i = slide.cart.findIndex(x => x.nom == this); | |
slide.cart[i].qte++; | |
slide.somme(); | |
} | |
removeFromCart() { | |
var i = slide.cart.findIndex(x => x.nom == this); | |
slide.cart.splice(i, 1); | |
slide.somme(); | |
} | |
render() { | |
return (<ul> | |
{ | |
slide.cart.map((p, i) => { | |
return (<li className="flex_r" key={i}> | |
<img src={p.src}/> | |
<span>{p.nom}</span> | |
<span className="cart_widget_qte">{p.qte}</span> | |
{ | |
this.props.control | |
? <div><i className="fas fa-plus cursor" onClick={this.plusCart.bind(p.nom)}></i> | |
<i className='fas fa-minus cursor' onClick={this.lessCart.bind(p.nom)}></i> | |
<i className="fas fa-times cursor" onClick={this.removeFromCart.bind(p.nom)}></i></div> | |
: null | |
} | |
</li>); | |
}) | |
} | |
</ul>) | |
} | |
} | |
export default view(Cart); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment