-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from miptleha/sprint-2/step-1
sprint-2/step-1
- Loading branch information
Showing
16 changed files
with
204 additions
and
104 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
38 changes: 22 additions & 16 deletions
38
src/components/burger-ingredients-item/burger-ingredients-item.jsx
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,45 @@ | ||
import { useState } from 'react'; | ||
import { useContext, useMemo } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { dataPropTypes } from '../../utils/dataPropTypes'; | ||
import { OrderContext } from '../../services/order-context'; | ||
import { BUN } from '../../utils/dataNames'; | ||
|
||
import styles from './burger-ingredients-item.module.css'; | ||
import { CurrencyIcon, Counter } from '@ya.praktikum/react-developer-burger-ui-components'; | ||
import IngredientDetails from '../ingredient-details/ingredient-details'; | ||
|
||
function BurgerIngredientItem({ item, count }) { | ||
const [show, setShow] = useState(false); | ||
function BurgerIngredientsItem({ item, onShowDetails }) { | ||
const { ingredients, bun } = useContext(OrderContext); | ||
|
||
function showDialog() { | ||
setShow(true); | ||
} | ||
const count = useMemo(() => { | ||
if (item.type === BUN && bun) { | ||
return bun._id === item._id ? 1 : 0; | ||
} | ||
else { | ||
const list = ingredients.filter(i => i._id === item._id); | ||
return list.length; | ||
} | ||
}, [item, bun, ingredients]); | ||
|
||
function hideDialog(e) { | ||
setShow(false); | ||
e.stopPropagation(); | ||
function showDialogItem() { | ||
onShowDetails(item); | ||
} | ||
|
||
return ( | ||
<li className={`${styles.card} mt-6 mb-8 ml-3 mr-2`} onClick={showDialog}> | ||
<li className={`${styles.card} mt-6 mb-8 ml-3 mr-2`} onClick={showDialogItem}> | ||
<img className={`${styles.image} ml-4 mr-4 mb-1`} src={item.image} alt="Ингридиент" /> | ||
<div className={`${styles.price} mb-1`}> | ||
<span className="text text_type_digits-default mr-2">{item.price}</span> | ||
<CurrencyIcon type="primary" /> | ||
</div> | ||
<div className={`${styles.title} text text_type_main-default`}>{item.name}</div> | ||
{count && count > 0 ? <Counter count={count} size="default" extraClass={styles.count} /> : undefined} | ||
{show && <IngredientDetails item={item} onClose={hideDialog} />} | ||
{count > 0 && <Counter count={count} size="default" extraClass={styles.count} />} | ||
</li> | ||
); | ||
} | ||
|
||
BurgerIngredientItem.propTypes = { | ||
BurgerIngredientsItem.propTypes = { | ||
item: dataPropTypes.isRequired, | ||
count: PropTypes.number | ||
onShowDetails: PropTypes.func.isRequired | ||
} | ||
|
||
export default BurgerIngredientItem; | ||
export default BurgerIngredientsItem; |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.