Skip to content

Commit

Permalink
faz fetch para obter ingredients
Browse files Browse the repository at this point in the history
  • Loading branch information
notnotgabriel committed Dec 12, 2018
1 parent edc9f92 commit db5a323
Showing 1 changed file with 12 additions and 31 deletions.
43 changes: 12 additions & 31 deletions dojos/20181212-jest-enzyme/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,10 @@ import React, { Component, Fragment } from 'react';

import CartSummaryModal from './Components/CartSummaryModal/CartSummaryModal';
import Ingredient from './Components/Ingredient/Ingredient';
import { getIngredients } from './services/ingredientsServices';

import './App.css';

const ingredients = [
{
id: '1',
name: "Pão italiano",
price: 10,
unique: true,
},
{
id: '2',
name: "Pão de brioche",
price: 10,
unique: true,
},
{
id: '3',
name: "Hamburguer de costela",
price: 10,
},
{
id: '4',
name: "Hamburguer de soja",
price: 10,
},
{
id: '5',
name: "Alface",
price: 10,
},
]

class App extends Component {
constructor() {
super();
Expand All @@ -45,6 +16,7 @@ class App extends Component {
total: 0,
},
isOrderSummaryOpen: false,
ingredients: [],
}
}

Expand All @@ -60,6 +32,15 @@ class App extends Component {
return null;
}

componentDidMount() {
getIngredients()
.then(ingredients => {
this.setState({
ingredients,
});
})
}

addIngredientToCart = (ingredient) => {
const { cart } = this.state;
const items = [
Expand Down Expand Up @@ -115,7 +96,7 @@ class App extends Component {
Resumo do pedido
</button>

{ingredients.map(ingredient => (
{this.state.ingredients.map(ingredient => (
<Ingredient
cart={this.state.cart}
ingredient={ingredient}
Expand Down

0 comments on commit db5a323

Please sign in to comment.