|
1 | 1 | import React from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | 3 |
|
4 | | -const RecipeList = props => { |
| 4 | +const RecipeListItem = ({ recipe, onClick, onFavorited, favorited }) => { |
5 | 5 | return ( |
6 | | - <div style={props.style}> |
| 6 | + <li |
| 7 | + key={recipe.name} |
| 8 | + className="py2 border-bottom border-bottom-dashed pointer" |
| 9 | + onClick={() => onClick(recipe.id)} |
| 10 | + > |
| 11 | + <span |
| 12 | + className="mr1 red" |
| 13 | + onClick={e => { |
| 14 | + e.stopPropagation(); |
| 15 | + onFavorited(recipe.id); |
| 16 | + }} |
| 17 | + role="img" |
| 18 | + aria-label="favorite" |
| 19 | + > |
| 20 | + {favorited ? '💖' : '⏍'} |
| 21 | + </span> |
| 22 | + <span>{recipe.name}</span> |
| 23 | + <span>{recipe.category}</span> |
| 24 | + </li> |
| 25 | + ); |
| 26 | +}; |
| 27 | + |
| 28 | +RecipeListItem.propTypes = { |
| 29 | + recipe: PropTypes.object, |
| 30 | + onClick: PropTypes.func, |
| 31 | + onFavorited: PropTypes.func, |
| 32 | + favorited: PropTypes.bool, |
| 33 | +}; |
| 34 | + |
| 35 | +const RecipeList = ({ style, recipes, favorites, ...props }) => { |
| 36 | + return ( |
| 37 | + <div style={style}> |
7 | 38 | <h2 className="h2">Menu</h2> |
8 | 39 | <ul className="list-reset"> |
9 | | - {props.recipes.map(recipe => ( |
10 | | - <li |
11 | | - key={recipe.name} |
12 | | - className="py2 border-bottom border-bottom-dashed pointer" |
13 | | - onClick={() => props.onClick(recipe.id)} |
14 | | - > |
15 | | - <span |
16 | | - className="mr1" |
17 | | - onClick={e => { |
18 | | - e.stopPropagation(); |
19 | | - props.onFavorited(recipe.id); |
20 | | - }} |
21 | | - role="img" |
22 | | - aria-label="favorite" |
23 | | - > |
24 | | - {props.favorites.includes(recipe.id) ? '<3' : '0'} |
25 | | - </span> |
26 | | - <span>{recipe.name}</span> |
27 | | - <span>{recipe.category}</span> |
28 | | - </li> |
| 40 | + {recipes.map(recipe => ( |
| 41 | + <RecipeListItem |
| 42 | + recipe={recipe} |
| 43 | + favorited={favorites.includes(recipe.id)} |
| 44 | + {...props} |
| 45 | + /> |
29 | 46 | ))} |
30 | 47 | </ul> |
31 | 48 | </div> |
|
0 commit comments