Skip to content
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
8 changes: 7 additions & 1 deletion 2-copy-of-code/lesson-18/data/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,10 @@ export async function loadCartFetch() {
const text = await response.text();
console.log(text);
return text;
}
}

// Extra feature: make the cart empty after creating an order.
export function resetCart() {
cart = [];
saveToStorage();
}
9 changes: 9 additions & 0 deletions 2-copy-of-code/lesson-18/scripts/amazon.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,13 @@ function renderProductsGrid() {
const search = document.querySelector('.js-search-bar').value;
window.location.href = `amazon.html?search=${search}`;
});

// Extra feature: searching by pressing "Enter" on the keyboard.
document.querySelector('.js-search-bar')
.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
const searchTerm = document.querySelector('.js-search-bar').value;
window.location.href = `amazon.html?search=${searchTerm}`;
}
});
}
4 changes: 3 additions & 1 deletion 2-copy-of-code/lesson-18/scripts/checkout/paymentSummary.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {cart} from '../../data/cart.js';
import {cart, resetCart} from '../../data/cart.js';
import {getProduct} from '../../data/products.js';
import {getDeliveryOption} from '../../data/deliveryOptions.js';
import {formatCurrency} from '../utils/money.js';
Expand Down Expand Up @@ -89,6 +89,8 @@ export function renderPaymentSummary() {
console.log('Unexpected error. Try again later.');
}

// Extra feature: make the cart empty after creating an order.
resetCart();
window.location.href = 'orders.html';
});
}
6 changes: 5 additions & 1 deletion 2-copy-of-code/lesson-18/scripts/tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ async function loadPage() {
const deliveryTime = dayjs(productDetails.estimatedDeliveryTime);
const percentProgress = ((today - orderTime) / (deliveryTime - orderTime)) * 100;

// Extra feature: display "delivered" on the tracking page
// if today's date is past the delivery date.
const deliveredMessage = today < deliveryTime ? 'Arriving on' : 'Delivered on';

const trackingHTML = `
<a class="back-to-orders-link link-primary" href="orders.html">
View all orders
</a>

<div class="delivery-date">
Arriving on ${
${deliveredMessage} ${
dayjs(productDetails.estimatedDeliveryTime).format('dddd, MMMM D')
}
</div>
Expand Down