diff --git a/src/App.js b/src/App.js index 54a2360..305d42d 100644 --- a/src/App.js +++ b/src/App.js @@ -38,6 +38,20 @@ function App() { } /> } /> } /> + + {/* CATCH-ALL ROUTE (404 Page) -------- This must always be the last route inside */} + + + +
+

404 - Page Not Found

+

The page you are looking for does not exist.

+
+ + } /> + +
diff --git a/src/components/CartHold.js b/src/components/CartHold.js index 0547d8d..be031a2 100644 --- a/src/components/CartHold.js +++ b/src/components/CartHold.js @@ -18,6 +18,10 @@ const CartHold = () => { return item.quantity * item.price; }).reduce((totalPrice, singleItemPrice) => totalPrice + singleItemPrice, 0); + // Handler to clear the entire cart + const handleClearCart = () => { + dispatch(cartActions.clearCart()); + }; return (
@@ -27,6 +31,15 @@ const CartHold = () => {

Your Cart

{cartLen} items

+ + {/* Added Clear Cart Button */} + +
diff --git a/src/components/NavBar.js b/src/components/NavBar.js index 7290e44..033f48c 100644 --- a/src/components/NavBar.js +++ b/src/components/NavBar.js @@ -10,188 +10,84 @@ import { Link } from 'react-router-dom'; import { useSelector } from 'react-redux'; const NavBar = () => { - const [show, setShow] = useState(false); - const [show2, setShow2] = useState(false); - const [show3, setShow3] = useState(false); - const [show4, setShow4] = useState(false); + // Access the total quantity from the cart state + const cartQuantity = useSelector((state) => state.cart.totalQuantity); + // Refactored: Single state to track the active dropdown menu + const [activeDropdown, setActiveDropdown] = useState(null); - const showHandler = () => { - setShow(true) - setShow2(false) - setShow3(false) - setShow4(false) + const handleMouseOver = (menuName) => { + setActiveDropdown(menuName); + }; - } - - const showHandler2 = () => { - setShow2(true) - setShow(false) - setShow3(false) - setShow4(false) - - } - - const showHandler3 = () => { - setShow3(true) - setShow(false) - setShow2(false) - setShow4(false) - } - - const showHandler4 = () => { - setShow4(true) - setShow(false) - setShow2(false) - setShow3(false) - - } - - - const dontShowHandler = () => { - setShow(false) - setShow2(false) - setShow3(false) - setShow4(false) - - - } + const handleMouseLeave = () => { + setActiveDropdown(null); + }; return (
- - -
+ + +
) } -export default NavBar - - - - - - - -/* - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - Link -
- -

Dropdown Menu inside a Navigation Bar

-

Hover over the "Dropdown" link to see the dropdown menu.

- - - - - - - - - - - - - -*/ - +export default NavBar; \ No newline at end of file diff --git a/src/redux-state/CartState.js b/src/redux-state/CartState.js index 656feb3..520e477 100644 --- a/src/redux-state/CartState.js +++ b/src/redux-state/CartState.js @@ -42,6 +42,11 @@ const cartSlice = createSlice({ existingItem.totalPrice = existingItem.totalPrice - existingItem.price; } }, + // New reducer to empty the entire cart at once + clearCart(state) { + state.items = []; + state.totalQuantity = 0; + }, } }) diff --git a/src/styles/Navbar.css b/src/styles/Navbar.css index 50d86cc..04c9885 100644 --- a/src/styles/Navbar.css +++ b/src/styles/Navbar.css @@ -171,4 +171,22 @@ li { width: 1.5px !important; top: 2.8rem !important; background-color: #031D44; -}/*# sourceMappingURL=Navbar.css.map */ \ No newline at end of file +}/*# sourceMappingURL=Navbar.css.map */ + +/* Custom styling for the cart badge */ +.navbar .relative { + position: relative; + display: flex; + align-items: center; +} + +/* Custom styling for the cart badge */ +.navbar span.bg-red-600 { + min-width: 18px; + height: 18px; + display: flex; + justify-content: center; + align-items: center; + font-size: 11px; + box-shadow: 0 2px 4px rgba(0,0,0,0.2); +} \ No newline at end of file