Skip to content

Commit f07a7b0

Browse files
author
CodeSigils
committed
move RecipeListItem to a new component
1 parent 2f4b26e commit f07a7b0

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"singleQuote": true,
3+
"tabWidth": 2,
34
"trailingComma": "all"
45
}

src/app/components/RecipeDetail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import classNames from 'classnames';
66
* `h3 p2 bg-white italic center ${props.className}` but there is the risk
77
* of a null value in our html. The classNames library will check if a CSS
88
* class is null and will not render it in html, so the above expression
9-
* can become: classNames('h3 p2 bg-white italic center, props.className')
9+
* can become: classNames('h3 p2 bg-white italic center', props.className)
1010
*/
1111

1212
const RecipeDetail = props => {

src/app/components/RecipeList.js

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,48 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33

4-
const RecipeList = props => {
4+
const RecipeListItem = ({ recipe, onClick, onFavorited, favorited }) => {
55
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}>
738
<h2 className="h2">Menu</h2>
839
<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+
/>
2946
))}
3047
</ul>
3148
</div>

0 commit comments

Comments
 (0)