-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
432 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<link href="https://fonts.googleapis.com/css?family=Comfortaa|Open+Sans" rel="stylesheet"> | ||
<link rel="stylesheet" href="assets/main.css"> | ||
<title>Food Menu</title> | ||
</head> | ||
<body> | ||
<header> | ||
<div class="site-title"> | ||
<h2><a href="index.html">Kiakia Food</a></h2> | ||
</div> | ||
<nav> | ||
<a href="#" class="nav-mobile">☰ menu</a> | ||
<ul> | ||
<li><a href="orders.html">All Orders</a></li> | ||
<li><a href="index.html">Log out</a></li> | ||
</ul> | ||
</nav> | ||
</header> | ||
|
||
<div class="wrapper"> | ||
<h2>Your Offerings</h2> | ||
<section class="container admin-menu"> | ||
<div class="food-card"> | ||
<img class="food-image" src="https://i.imgur.com/Bfn1CxC.jpg" alt="Turkey Wings"> | ||
<div class="food-details"> | ||
<div data-foodid="2" class="food-details__legend"> | ||
<h4>Turkey Wings</h4> | ||
<p>₦1,000</p> | ||
</div> | ||
<div class="food-details__action"> | ||
<button>delete</button> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="food-card"> | ||
<img class="food-image" src="https://i.imgur.com/z490cis.jpg" alt="Chicken Wings"> | ||
<div class="food-details"> | ||
<div data-foodid="3" class="food-details__legend"> | ||
<h4>Chicken Wings</h4> | ||
<p>₦1,200</p> | ||
</div> | ||
<div class="food-details__action"> | ||
<button>delete</button> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="food-card"> | ||
<img class="food-image" src="https://i.imgur.com/mTHYwlc.jpg" alt="Tasty Prawns"> | ||
<div class="food-details"> | ||
<div data-foodid="4" class="food-details__legend"> | ||
<h4>Tasty Prawns</h4> | ||
<p>₦2,200</p> | ||
</div> | ||
<div class="food-details__action"> | ||
<button>delete</button> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
<a href="add-food.html"><button class="btn-primary">Add New Item</button></a> | ||
</div> | ||
|
||
<footer> | ||
<div class="footer-left"> | ||
<p>kiakia food</p> | ||
</div> | ||
<div class="footer-right"> | ||
<p>© 2018</p> | ||
</div> | ||
</footer> | ||
|
||
<script src="assets/main.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Get all buttons | ||
const buyButtons = document.querySelectorAll('.food-details__action > button'); | ||
|
||
function addToCart() { | ||
if(!localStorage.getItem('cart')) localStorage.setItem('cart', '{}'); | ||
const cart = JSON.parse(localStorage.getItem('cart')); | ||
const foodDetails = this.parentNode.previousElementSibling; | ||
const foodImage = foodDetails.parentNode.previousElementSibling.src; | ||
const foodId = foodDetails.dataset.foodid | ||
const foodName = foodDetails.querySelector('h4').innerText; | ||
const foodPrice = foodDetails.querySelector('p').innerText; | ||
|
||
if(!cart.hasOwnProperty(foodId)) { | ||
cart[foodId] = { foodName, foodPrice, foodImage } | ||
} else { | ||
return flashMessage('Item already in cart', 'error'); | ||
} | ||
|
||
localStorage.setItem('cart', JSON.stringify(cart)); | ||
flashMessage('Item added to cart', 'success'); | ||
} | ||
|
||
|
||
// Event Listeners | ||
buyButtons.forEach(button => button.addEventListener('click', addToCart)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
function checkoutCardBlueprint(id, foodName, foodPrice) { | ||
return ` | ||
<div data-foodid=${id} class="food-card-checkout"> | ||
<div class="food-card-checkout__details"> | ||
<h4>${foodName}</h4> | ||
<p>${foodPrice}</p> | ||
</div> | ||
<button>Remove</button> | ||
</div> | ||
`; | ||
} | ||
|
||
// Populate Cart Items on Page Load | ||
(() => { | ||
const cartItems = JSON.parse(localStorage.getItem('cart')); | ||
if(!Object.keys(cartItems).length) { | ||
document.querySelector('#checkout').remove(); | ||
return document.querySelector('section.checkout').innerHTML = '<div>No items in cart!</div>'; | ||
} | ||
|
||
const formatted = []; | ||
for (const food in cartItems) { | ||
formatted.push(checkoutCardBlueprint(food, cartItems[food].foodName, cartItems[food].foodPrice)); | ||
} | ||
document.querySelector('section.checkout').innerHTML = formatted.join(''); | ||
})(); | ||
|
||
// | ||
const removeButtons = document.querySelectorAll('.food-card-checkout > button') | ||
|
||
function removeFromCart() { | ||
const cart = JSON.parse(localStorage.getItem('cart')); | ||
const foodCard = this.parentNode; | ||
const foodId = foodCard.dataset.foodid; | ||
delete cart[foodId]; | ||
|
||
localStorage.setItem('cart', JSON.stringify(cart)); | ||
foodCard.remove(); | ||
} | ||
|
||
removeButtons.forEach(button => button.addEventListener('click', removeFromCart)); |
Oops, something went wrong.