Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
14 changes: 13 additions & 1 deletion 14 2-copy-of-code/lesson-18/data/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,16 @@ export function addOrder(order) {

function saveToStorage() {
localStorage.setItem('orders', JSON.stringify(orders));
}
}

export function getOrder(orderId) {
let matchingOrder;

orders.forEach((order) => {
if (order.id === orderId) {
matchingOrder = order;
}
});

return matchingOrder;
}
65 changes: 65 additions & 0 deletions 65 2-copy-of-code/lesson-18/scripts/tracking.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {getOrder} from '../data/orders.js';
import {getProduct, loadProductsFetch} from '../data/products.js';
import dayjs from 'https://unpkg.com/dayjs@1.11.10/esm/index.js';

async function loadPage() {
await loadProductsFetch();

const url = new URL(window.location.href);
const orderId = url.searchParams.get('orderId');
const productId = url.searchParams.get('productId');

const order = getOrder(orderId);
const product = getProduct(productId);

// Get additional details about the product like
// the estimated delivery time.
let productDetails;
order.products.forEach((details) => {
if (details.productId === product.id) {
productDetails = details;
}
});

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

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

<div class="product-info">
${product.name}
</div>

<div class="product-info">
Quantity: ${productDetails.quantity}
</div>

<img class="product-image" src="${product.image}">

<div class="progress-labels-container">
<div class="progress-label">
Preparing
</div>
<div class="progress-label current-status">
Shipped
</div>
<div class="progress-label">
Delivered
</div>
</div>

<div class="progress-bar-container">
<div class="progress-bar"></div>
</div>
`;

document.querySelector('.js-order-tracking').innerHTML = trackingHTML;
}

loadPage();
41 changes: 2 additions & 39 deletions 41 2-copy-of-code/lesson-18/tracking.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,47 +52,10 @@
</div>

<div class="main">
<div class="order-tracking">
<a class="back-to-orders-link link-primary" href="orders.html">
View all orders
</a>

<div class="delivery-date">
Arriving on Monday, June 13
</div>

<div class="product-info">
Black and Gray Athletic Cotton Socks - 6 Pairs
</div>

<div class="product-info">
Quantity: 1
</div>

<img class="product-image" src="images/products/athletic-cotton-socks-6-pairs.jpg">

<div class="progress-labels-container">
<div class="progress-label">
Preparing
</div>
<div class="progress-label current-status">
Shipped
</div>
<div class="progress-label">
Delivered
</div>
</div>

<div class="progress-bar-container">
<div class="progress-bar"></div>
</div>
<div class="order-tracking js-order-tracking">
</div>
</div>

<script>
const url = new URL(window.location.href);
console.log(url.searchParams.get('orderId'));
console.log(url.searchParams.get('productId'));
</script>
<script type="module" src="scripts/tracking.js"></script>
</body>
</html>
Morty Proxy This is a proxified and sanitized view of the page, visit original site.