diff --git a/src/components/Burger/BuildControls/BuildControl/BuildControl.js b/src/components/Burger/BuildControls/BuildControl/BuildControl.js
index 10b48e5..4a8ad49 100644
--- a/src/components/Burger/BuildControls/BuildControl/BuildControl.js
+++ b/src/components/Burger/BuildControls/BuildControl/BuildControl.js
@@ -5,8 +5,13 @@ import classes from './BuildControl.css';
const buildControl = (props) => (
{props.name}
-
-
+
+
)
diff --git a/src/components/Burger/BuildControls/BuildControls.js b/src/components/Burger/BuildControls/BuildControls.js
index bced256..ac5563f 100644
--- a/src/components/Burger/BuildControls/BuildControls.js
+++ b/src/components/Burger/BuildControls/BuildControls.js
@@ -16,7 +16,9 @@ const buildControls = (props) => (
props.ingredientAdded(ctrl.type) }/>
+ added={() => props.ingredientAdded(ctrl.type) }
+ removed={() => props.ingredientRemoved(ctrl.type)}
+ disabled={props.disabled[ctrl.type]} />
))}
)
diff --git a/src/containers/BurgerBuilder/BurgerBuilder.js b/src/containers/BurgerBuilder/BurgerBuilder.js
index bd9dcc2..cd91a4d 100644
--- a/src/containers/BurgerBuilder/BurgerBuilder.js
+++ b/src/containers/BurgerBuilder/BurgerBuilder.js
@@ -32,7 +32,8 @@ class BurgerBuilder extends Component {
updatedIngredient[type] = newCount;
const priceAddition = INGREDIENT_PRICE[type];
- const newPrice = this.state.totalPrice + priceAddition;
+ const oldPrice = this.state.totalPrice;
+ const newPrice = oldPrice + priceAddition;
this.setState({
totalPrice: newPrice,
ingredients: updatedIngredient,
@@ -40,15 +41,41 @@ class BurgerBuilder extends Component {
}
removeIngredientHandler = (type) => {
+ const oldCount = this.state.ingredients[type];
+ if (oldCount <= 0){
+ return;
+ }
+ const newCount = oldCount - 1;
+ const updatedIngredient = {
+ ...this.state.ingredients,
+ };
+ updatedIngredient[type] = newCount;
+ const priceDeduction = INGREDIENT_PRICE[type];
+ const oldPrice = this.state.totalPrice;
+ const newPrice = oldPrice - priceDeduction ;
+ this.setState({
+ totalPrice: newPrice,
+ ingredients: updatedIngredient,
+ });
}
render() {
+ const disabledInfo = {
+ ...this.state.ingredients
+ };
+
+ for (let key in disabledInfo) {
+ disabledInfo[key] = disabledInfo[key] <= 0;
+ }
+
return (
+ ingredientAdded={this.addIngredientHandler}
+ ingredientRemoved={this.removeIngredientHandler}
+ disabled={disabledInfo} />
);
};