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 MealPlanItem from './MealPlanItem'; | |
import _ from 'lodash'; | |
class MealPlan extends Component { | |
state = { | |
meal: '', | |
meals: [], | |
showAddMealMessage: false | |
}; |
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 from 'react'; | |
const MealPlanItem = (props) => { | |
return <li>{props.meal} <button>Delete</button></li>; | |
} | |
export default MealPlanItem; |
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 from 'react'; | |
const MealPlanItem = (props) => { | |
return <li>{props.meal} <button onClick={props.handleDelete}>Delete</button></li>; | |
} | |
export default MealPlanItem; |
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
removeMeal(mealToRemove) { | |
const meals = this.state.meals.filter(meal => meal !== mealToRemove); | |
this.setState({ | |
meals: meals | |
}); | |
} |
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 MealPlanItem from './MealPlanItem'; | |
import _ from 'lodash'; | |
class MealPlan extends Component { | |
state = { | |
meal: '', | |
meals: [], | |
showAddMealMessage: false | |
}; |
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
handleSubmit = (event) => { | |
event.preventDefault() | |
const meal = this.state.meal; | |
if (this.state.meals.indexOf(meal) === -1) { | |
this.setState({ | |
meals: [...this.state.meals, meal], | |
meal: "" | |
}); | |
} | |
} |
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 MealPlanItem from './MealPlanItem'; | |
import _ from 'lodash'; | |
class MealPlan extends Component { | |
state = { | |
meal: '', | |
meals: [], | |
showMessage: '' | |
}; |
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
// Array of Strings - What we have now. Can't be considered as an option anymore | |
const meals = ['Spaghetti carbonara', 'Oatmeal']; | |
// Array of object - Can be consideres as an option , but it could be tricky to manipulate | |
// We need to have in mind that we will be changing the array as it represents our state | |
const meals = [ | |
{ | |
title: 'Spaghetti carbonara', | |
completed: false | |
}, |
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 from 'react'; | |
const MealPlanItem = (props) => { | |
return( | |
<li> | |
<span onClick={props.handleMealClick} >{props.title}</span> | |
{props.completed || <button onClick={props.handleDelete}>Delete</button>} | |
</li> | |
); | |
} |
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
componentWillMount() { | |
this.setState({ | |
meals: { | |
"Spaghetti carboanra": { | |
completed: false | |
}, | |
"Risotto": { | |
completed: false | |
}, | |
"Oatmeal": { |