File tree Expand file tree Collapse file tree 4 files changed +24
-3
lines changed
Expand file tree Collapse file tree 4 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -89,4 +89,10 @@ export async function loadCartFetch() {
8989 const text = await response . text ( ) ;
9090 console . log ( text ) ;
9191 return text ;
92- }
92+ }
93+
94+ // Extra feature: make the cart empty after creating an order.
95+ export function resetCart ( ) {
96+ cart = [ ] ;
97+ saveToStorage ( ) ;
98+ }
Original file line number Diff line number Diff line change @@ -112,4 +112,13 @@ function renderProductsGrid() {
112112 const search = document . querySelector ( '.js-search-bar' ) . value ;
113113 window . location . href = `amazon.html?search=${ search } ` ;
114114 } ) ;
115+
116+ // Extra feature: searching by pressing "Enter" on the keyboard.
117+ document . querySelector ( '.js-search-bar' )
118+ . addEventListener ( 'keydown' , ( event ) => {
119+ if ( event . key === 'Enter' ) {
120+ const searchTerm = document . querySelector ( '.js-search-bar' ) . value ;
121+ window . location . href = `amazon.html?search=${ searchTerm } ` ;
122+ }
123+ } ) ;
115124}
Original file line number Diff line number Diff line change 1- import { cart } from '../../data/cart.js' ;
1+ import { cart , resetCart } from '../../data/cart.js' ;
22import { getProduct } from '../../data/products.js' ;
33import { getDeliveryOption } from '../../data/deliveryOptions.js' ;
44import { formatCurrency } from '../utils/money.js' ;
@@ -89,6 +89,8 @@ export function renderPaymentSummary() {
8989 console . log ( 'Unexpected error. Try again later.' ) ;
9090 }
9191
92+ // Extra feature: make the cart empty after creating an order.
93+ resetCart ( ) ;
9294 window . location . href = 'orders.html' ;
9395 } ) ;
9496}
Original file line number Diff line number Diff line change @@ -26,13 +26,17 @@ async function loadPage() {
2626 const deliveryTime = dayjs ( productDetails . estimatedDeliveryTime ) ;
2727 const percentProgress = ( ( today - orderTime ) / ( deliveryTime - orderTime ) ) * 100 ;
2828
29+ // Extra feature: display "delivered" on the tracking page
30+ // if today's date is past the delivery date.
31+ const deliveredMessage = today < deliveryTime ? 'Arriving on' : 'Delivered on' ;
32+
2933 const trackingHTML = `
3034 <a class="back-to-orders-link link-primary" href="orders.html">
3135 View all orders
3236 </a>
3337
3438 <div class="delivery-date">
35- Arriving on ${
39+ ${ deliveredMessage } ${
3640 dayjs ( productDetails . estimatedDeliveryTime ) . format ( 'dddd, MMMM D' )
3741 }
3842 </div>
You can’t perform that action at this time.
0 commit comments