Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,59 @@
import { useState } from "react";

import Footer from "./Footer";
import Header from "./Header";
import Menu from "./Menu";



function App() {

const [currentOrder, setCurrentOrder] = useState([])
const [total, setTotal] = useState(0)

const handleOrder = (item) => {
setCurrentOrder([...currentOrder, item])
setTotal(total + item.price)
}

const removeOrder = (index, price) => {
const updatedOrder = [...currentOrder];
updatedOrder.splice(index, 1);
setCurrentOrder(updatedOrder);
setTotal(total - price)

}

const closeOrder = () => {
setTotal(0)
setCurrentOrder([])
}


return (
<div className="App">
<Header />
<main>
<aside>
<table></table>
<Menu handleOrder = {handleOrder}/>
</aside>
<section>
<div>
<h2>Current Order</h2>
<ul></ul>
<h4>Total:</h4>
<ul>
{currentOrder.map((item, i) =>
<li key={i}>
<span onClick={() => {removeOrder(i, item.price)}}>❌</span>
<span>{item.name}</span>
<span>${item.price}</span>
</li>

)}
</ul>
<h4>Total:${total}</h4>
<div>
<button>Tidy order</button>
<button>Close order</button>
<button onClick= {closeOrder}>Close order</button>
</div>
</div>
</section>
Expand All @@ -27,3 +64,4 @@ function App() {
}

export default App;

13 changes: 13 additions & 0 deletions src/Menu.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@








.header {
text-align: center;
text-decoration: 2px underline black;
padding-top: 0em;
}
37 changes: 37 additions & 0 deletions src/Menu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

import menuItems from "./data";

import "./Menu.css"



function Menu({handleOrder}) {



return (
<div>
<h2 className= "header">Welcome here is our menu, Enjoy !</h2>
<table>
<tbody>
{menuItems.map((item) =>

<tr key= {item.id} onClick={() => handleOrder(item)}>

<td>{item.image}</td>
<td className= "item-name"> <span>{item.name}</span> <br/>
<span>
{ "🌶️".repeat(item.spiceLevel)}
</span></td>
<td> $ {item.price}</td>
</tr>
)}
</tbody>
</table>
</div>
)
}



export default Menu
4 changes: 2 additions & 2 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import ReactDOM from "react-dom";
import ReactDOM from "react-dom/client";
import "./index.css";

import App from "./App";

ReactDOM.render(<App />, document.getElementById("root"));
ReactDOM.createRoot(document.getElementById("root")).render(<App />);