diff --git a/src/App.css b/src/App.css new file mode 100644 index 0000000..3707d25 --- /dev/null +++ b/src/App.css @@ -0,0 +1,111 @@ +/* App.css */ +.App { + display: flex; + flex-direction: column; + min-height: 100vh; +} + +.content { + display: flex; + gap: 20px; + padding: 20px; +} + +.menu { + flex: 1; + display: inline-block; +} + +.menu h2 { + margin-bottom: 10px; +} + +.menu-table { + width: 100%; + border-collapse: collapse; +} + +.menu-table td { + padding: 10px; + border: 1px solid #ccc; + text-align: center; +} + +.menu-table img { + max-width: 100px; + max-height: 100px; + object-fit: cover; +} + +.item-details { + flex: 3; + display: flex; + flex-direction: column; + align-items: flex-start;/ +} + +.current-order { + flex: 1; + display: inline-block; +} + +.current-order h2 { + margin-bottom: 10px; +} + +.current-order button { + margin-bottom: 10px; + padding: 10px 20px; + background-color: #007bff; + color: white; + border: none; + border-radius: 4px; + cursor: pointer; +} + +.tidy-button { + margin: 0 auto; +} + +.order-table { + width: 100%; + border-collapse: collapse; +} + +.order-table td { + padding: 10px; + border: 1px solid #ccc; + text-align: center; +} + +.order-table td button { + color: red; + color: white; + border: none; + cursor: pointer; + background-color: transparent; + +} + + +footer { + background-color: #f9f9f9; + padding: 10px; + text-align: center; +} + + +header { + background-color: #007bff; + color: white; + padding: 10px; + text-align: center; +} + + +body { + margin: 0; + font-family: Arial, sans-serif; +} + + diff --git a/src/App.jsx b/src/App.jsx index 0218d5b..f93b49f 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,29 +1,124 @@ -import Footer from "./Footer"; +// App.js +import React, { useState } from "react"; +import menu from "./data"; import Header from "./Header"; +import Footer from "./Footer"; +import "./App.css"; + +const App = () => { + const [currentOrder, setCurrentOrder] = useState([]); + const [totalCost, setTotalCost] = useState(0); + const [tidyOrder, setTidyOrder] = useState(false); + + const addItemToOrder = (item) => { + setCurrentOrder([...currentOrder, item]); + setTotalCost((prevTotal) => prevTotal + item.price); + }; + + const removeItemFromOrder = (itemId) => { + const itemToRemove = currentOrder.find((item) => item.id === itemId); + if (itemToRemove.quantity > 1) { + const updatedOrder = currentOrder.map((item) => + item.id === itemId ? { ...item, quantity: item.quantity - 1 } : item + ); + setCurrentOrder(updatedOrder); + setTotalCost((prevTotal) => prevTotal - itemToRemove.price); + } else { + const updatedOrder = currentOrder.filter((item) => item.id !== itemId); + setCurrentOrder(updatedOrder); + setTotalCost((prevTotal) => prevTotal - itemToRemove.price); + } + }; + + const closeOrder = () => { + setCurrentOrder([]); + setTotalCost(0); + setTidyOrder(false); + }; + + const tidyCurrentOrder = () => { + const orderMap = currentOrder.reduce((acc, item) => { + if (!acc[item.id]) { + acc[item.id] = { ...item, quantity: 1 }; + } else { + acc[item.id].quantity += 1; + } + return acc; + }, {}); + + const tidiedOrder = Object.values(orderMap); + setCurrentOrder(tidiedOrder); + setTidyOrder(true); + }; -function App() { return (
-
- -
-
-

Current Order

-
    -

    Total:

    -
    - - -
    -
    -
    -
    + +
    + {/* Menu */} +
    +

    Menu

    + + + {menu.map((item) => ( + addItemToOrder(item)}> + + + + + ))} + +
    + {item.name} + + {item.name} +
    + + {Array(item.spiceLevel) + .fill("🌶️") + .join("")} + +
    ${item.price}
    +
    + + {/* Current Order */} +
    +

    Current Order

    + + + + {tidyOrder + ? currentOrder.map((item) => ( + + + + + + )) + : currentOrder.map((item) => ( + + + + + + ))} + +
    + + {item.name} x {item.quantity}${item.price * item.quantity}
    + + {item.name}${item.price}
    +

    Total: ${totalCost}

    + +
    +
    +
    ); -} +}; export default App;