diff --git a/README.md b/README.md index f9d93a2..e0310e5 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This is a simple E-Commerce site made with React and TailwindCSS. Your job is to 1. [Cart Persistence on Refresh](https://github.com/developer-job-simulation/react-ecommerce/issues/2) 1. [Add Product Filters Functionality](https://github.com/developer-job-simulation/react-ecommerce/issues/3) 1. ~~[Product Fetch is Causing Infinite Loop](https://github.com/developer-job-simulation/react-ecommerce/issues/4)~~ -1. [Need to display 'Empty Cart' When Cart is Empty on Cart Page](https://github.com/developer-job-simulation/react-ecommerce/issues/5) +1. ~~[Need to display 'Empty Cart' When Cart is Empty on Cart Page](https://github.com/developer-job-simulation/react-ecommerce/issues/5)~~ 1. ~~[Update Cart in Nav with Cart Size](https://github.com/developer-job-simulation/react-ecommerce/issues/6)~~ 1. ~~[Cart not closing when User Clicks Gray Region](https://github.com/developer-job-simulation/react-ecommerce/issues/7)~~ 1. [Subtotal Is not Implemented on Cart Page](https://github.com/developer-job-simulation/react-ecommerce/issues/8) diff --git a/src/Components/Cart.jsx b/src/Components/Cart.jsx index 16b66db..34739d5 100644 --- a/src/Components/Cart.jsx +++ b/src/Components/Cart.jsx @@ -1,6 +1,69 @@ import { Dialog, Transition } from "@headlessui/react"; -import { XIcon } from "@heroicons/react/outline"; +import { XIcon, ShoppingCartIcon } from "@heroicons/react/outline"; import React, { Fragment } from "react"; +import { getCartSize } from "../Utilities"; + +function CartItemList({ cart, updateCart }) { + return ( +
+
+ +
+
+ ) +} + +function EmptyCartDisplay() { + return ( +
+ +

Your Cart is Empty.

+
+ ); +} export default function Cart({ open, setOpen, cart, updateCart }) { return ( @@ -37,7 +100,7 @@ export default function Cart({ open, setOpen, cart, updateCart }) { >
-
+
Shopping cart
@@ -52,54 +115,10 @@ export default function Cart({ open, setOpen, cart, updateCart }) {
-
-
-
    - {cart.map((product) => ( -
  • -
    - {product.imageAlt} -
    - -
    -
    -
    -

    {product.name}

    -

    ${product.price}

    -
    -
    -
    -

    Qty {product.quantity}

    - -
    - -
    -
    -
    -
  • - ))} -
-
-
+ { getCartSize(cart) > 0 ? + : + + }
diff --git a/src/Components/NavBar.jsx b/src/Components/NavBar.jsx index 84f3e3f..f186f87 100644 --- a/src/Components/NavBar.jsx +++ b/src/Components/NavBar.jsx @@ -1,9 +1,6 @@ import { ShoppingBagIcon } from "@heroicons/react/outline"; import React from "react"; - -function getCartSize(cart) { - return cart.reduce((prev, curr) => prev + curr.quantity, 0); -} +import { getCartSize } from "../Utilities"; export default function NavBar({ setOpen, cart }) { return ( diff --git a/src/Utilities/index.js b/src/Utilities/index.js new file mode 100644 index 0000000..fb1f92f --- /dev/null +++ b/src/Utilities/index.js @@ -0,0 +1,3 @@ +export function getCartSize(cart) { + return cart.reduce((prev, curr) => prev + curr.quantity, 0); +} diff --git a/todo.md b/todo.md index dc049ff..bf4266a 100644 --- a/todo.md +++ b/todo.md @@ -11,6 +11,9 @@ - Issue #4 Todos - [x] Fix the effect hook to stop infinite loop +- Issue #5 Todos + - [x] Implement mockup on cart page (when cart is empty) using flexbox + - Issue #6 Todos - [x] Link the cart size to the nav