@@ -8,24 +8,18 @@ import Modal from '../../components/UI/Modal/Modal'
88import OrderSummary from '../../components/Burger/OrderSummary/OrderSummary'
99import axios from '../../axios-orders'
1010import Spinner from '../../components/UI/Spinner/Spinner'
11- import * as actionTypes from '../../store/actions' ;
11+ import * as actions from '../../store/actions/index ' ;
1212
1313
1414class BurgerBuilder extends Component {
1515 state = {
1616 purchasing : false ,
17- loading : false ,
18- error : false
17+ // loading: false,
18+ // error: false
1919 }
2020
2121 componentDidMount ( ) {
22- // axios.get('https://myburger-72558.firebaseio.com/ingredients.json')
23- // .then(response => {
24- // this.setState({ ingredients: response.data });
25- // })
26- // .catch(error => {
27- // this.setState({error: true});
28- // })
22+ this . props . onInitIngedients ( ) ;
2923 }
3024
3125 updatePurchaseState ( ingredients ) {
@@ -36,7 +30,6 @@ class BurgerBuilder extends Component {
3630 . reduce ( ( sum , curVal ) => {
3731 return sum = sum + curVal ;
3832 } , 0 ) ;
39- debugger ;
4033 return sum > 0 ;
4134 }
4235
@@ -49,7 +42,7 @@ class BurgerBuilder extends Component {
4942 }
5043
5144 purchaseContiueHandler = ( ) => {
52-
45+ this . props . onInitPurchase ( ) ;
5346 this . props . history . push ( {
5447 pathname :'/checkout'
5548 } ) ;
@@ -62,7 +55,7 @@ class BurgerBuilder extends Component {
6255 for ( let key in disabledInfo ) {
6356 disabledInfo [ key ] = disabledInfo [ key ] <= 0 ;
6457 }
65- let burger = this . state . error ? < p > Ingredients can't be loaded</ p > : < Spinner />
58+ let burger = this . props . error ? < p > Ingredients can't be loaded</ p > : < Spinner />
6659 let orderSummary = null ;
6760 if ( this . props . ings ) {
6861 burger = (
@@ -86,9 +79,9 @@ class BurgerBuilder extends Component {
8679 continuePurchase = { this . purchaseContiueHandler } /> ;
8780 }
8881
89- if ( this . state . loading ) {
90- orderSummary = < Spinner /> ;
91- }
82+ // if (this.state.loading) {
83+ // orderSummary = <Spinner />;
84+ // }
9285
9386 return (
9487 < Aux >
@@ -103,20 +96,17 @@ class BurgerBuilder extends Component {
10396
10497const mapStateToProps = ( state ) => {
10598 return {
106- ings : state . ingredients ,
107- totalSum : state . totalPrice
99+ ings : state . burgerBuilder . ingredients ,
100+ totalSum : state . burgerBuilder . totalPrice ,
101+ error : state . burgerBuilder . error
108102 }
109103}
110104const mapDispatchToProps = dispath => {
111105 return {
112- onIngredientAdded : ( ingName ) => dispath ( {
113- type : actionTypes . ADD_INGREDIENTS ,
114- ingredientName : ingName
115- } ) ,
116- onIngredientRemoved : ( ingName ) => dispath ( {
117- type : actionTypes . REMOVE_INGREDIENTS ,
118- ingredientName : ingName
119- } )
106+ onIngredientAdded : ( ingName ) => dispath ( actions . addIngredient ( ingName ) ) ,
107+ onIngredientRemoved : ( ingName ) => dispath ( actions . removeIngredient ( ingName ) ) ,
108+ onInitIngedients : ( ) => dispath ( actions . initIngredients ( ) ) ,
109+ onInitPurchase : ( ) => dispath ( actions . purchaseInit ( ) )
120110 }
121111}
122112export default connect ( mapStateToProps , mapDispatchToProps ) ( WithErrorHandler ( BurgerBuilder , axios ) )
0 commit comments