Skip to content

Commit

Permalink
add cart page and link nav icon
Browse files Browse the repository at this point in the history
  • Loading branch information
letioneill committed Jun 16, 2024
1 parent b80c897 commit 856cbdb
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 5 deletions.
98 changes: 98 additions & 0 deletions checkout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Checkout | Sparrow Photography</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body class="gallery">

<nav class="nav">
<a class="logo" href="index.html" aria-label="Sparrow Photography">
<svg class="logo-svg">
<use href="i/logos.svg#pirate" </use>
</svg>
<span class="logo-text">
<span>sparrow</span>
<span>Photography</span>
</span>
</a>
<div class="nav-items">
<a aria-current="page" href="checkout.html"">
<span aria-hidden="true">&#x1f6d2;</span> Cart <span id="cart-count"></span>
</a>
</div>
</nav>

<h1>Checkout</h1>
<div id="app">Loading...</div>


<footer>
<p><em>Photos by Jack Sparrow. All rights reserved.</em></p>
</footer>


<script type="module">
import { render } from "https://cdn.jsdelivr.net/npm/reefjs@12/dist/reef.es.min.js";
import { getPhotos } from "./components/api.js";
import {inCart} from "./components/cart.js";

// Get the #app element
let app = document.querySelector("#app");

/**
* Generate the cart HTML
* @param {Array} photos The photo data
* @return {String} The cart HTML string
*/
function cartHTML(photos) {

// Get the photos that are in the cart
let photosInCart = photos.filter(function (photo) {
return inCart(photo.id);
});

// If there are no items in the cart
if (!photosInCart.length) {
return '<p>You have no photos in your cart.</p>';
}

// Otherwise, generate table
return `
<table>
<thead>
<tr>
<th width="150">Photo</th>
<th>Name</th>
<th class="text-right">Price</th>
</tr>
</thead>
<tbody>
${photosInCart.map(function (photo) {
return `
<tr>
<td><img alt="${photo.description}" src="${photo.url}"></td>
<td>${photo.name}</td>
<td class="text-right">$${photo.price}</td>
</tr>`;
}).join("")}
</tbody>
</table>
<p class="text-right">
<strong>Total:</strong> $${photosInCart.reduce(function (total, photo) {
return total + photo.price;
}, 0)}
</p>`;
}

// Initialize
getPhotos().then(function (photos) {
render(app, cartHTML(photos));
});
</script>

</body>
</html>
6 changes: 4 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Sparrow Photography</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body class="gallery">

Expand All @@ -20,7 +20,9 @@
</span>
</a>
<div class="nav-items">
<span aria-hidden="true">&#x1f6d2;</span> Cart <span id="cart-count"></span>
<a href="checkout.html">
<span aria-hidden="true">&#x1f6d2;</span> Cart <span id="cart-count"></span>
</a>
</div>
</nav>

Expand Down
6 changes: 4 additions & 2 deletions photo.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Sparrow Photography</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body class="photo-detail">

Expand All @@ -20,7 +20,9 @@
</span>
</a>
<div class="nav-items">
<span aria-hidden="true">&#x1f6d2;</span> Cart <span id="cart-count"></span>
<a href="checkout.html">
<span aria-hidden="true">&#x1f6d2;</span> Cart <span id="cart-count"></span>
</a>
</div>
</nav>

Expand Down
20 changes: 20 additions & 0 deletions src/css/components/cart.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Table Styles
*/

table {
border-collapse: collapse;
border-spacing: 0;
margin-bottom: 1em;
max-width: 100%;
width: 100%;
}


/**
* Utility Classes
*/

.text-right {
text-align: right;
}
2 changes: 1 addition & 1 deletion styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 856cbdb

Please sign in to comment.