carttem and funcs

This commit is contained in:
Tyrel Souza 2022-09-26 13:26:51 -04:00
parent 135e4a9a1d
commit ce7158fc15
No known key found for this signature in database
GPG Key ID: F3614B02ACBE438E
2 changed files with 27 additions and 9 deletions

View File

@ -1,15 +1,33 @@
import React from "react" import React, { useContext } from "react"
import classes from "./Cart.module.css" import classes from "./Cart.module.css"
import CartItem from "./CartItem"
import Modal from "../UI/Modal" import Modal from "../UI/Modal"
import CartContext from "../../store/cart-context"
function Cart(props) { function Cart(props) {
const cartCtx = useContext(CartContext)
const totalAmount = `$${cartCtx.totalAmount.toFixed(2)}`
const hasItems = cartCtx.items.length > 0
const cartItemRemoveHandler = id => {}
const cartItemAddHandler = items => {}
const cartItems = ( const cartItems = (
<ul className={classes["cart-items"]}> <ul className={classes["cart-items"]}>
{[{ id: "c1", name: "Sushi", amount: 2, price: 12.99 }].map( {cartCtx.items.map((item) => (
(item) => ( <CartItem
<li>{item.name}</li> key={item.id}
) name={item.name}
)} amount={item.amount}
price={item.price}
onRemove={cartItemRemoveHandler.bind(null, item.id)}
onAdd={cartItemAddHandler.bind(null, item)}
>
{item.name}
</CartItem>
))}
</ul> </ul>
) )
@ -18,7 +36,7 @@ function Cart(props) {
{cartItems} {cartItems}
<div className={classes.total}> <div className={classes.total}>
<span>Total Amount</span> <span>Total Amount</span>
<span>35.62</span> <span>{totalAmount}</span>
</div> </div>
<div className={classes.actions}> <div className={classes.actions}>
<button <button
@ -27,7 +45,7 @@ function Cart(props) {
> >
Close Close
</button> </button>
<button className={classes.button}>Order</button> {hasItems && <button className={classes.button}>Order</button>}
</div> </div>
</Modal> </Modal>
) )

View File

@ -3,7 +3,7 @@
margin: 0; margin: 0;
padding: 0; padding: 0;
max-height: 20rem; max-height: 20rem;
overflow: auto; overflow: scroll;
} }
.total { .total {