Skip to content

Commit

Permalink
update fav/cart count on load
Browse files Browse the repository at this point in the history
The numbers will start with the total of favorites and items in
cart, stored on localStorage.
  • Loading branch information
HectorVilas committed May 2, 2023
1 parent 849f3d4 commit 4198c6a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modules/header.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { goToPage, toggleNav } from "./functions.js";
import { storedData } from "./storedData.js";

const svgNs = 'http://www.w3.org/2000/svg';

Expand Down Expand Up @@ -36,6 +37,9 @@ function logo() {
}

function nav() {
const favAmount = storedData.getCounts().favsCount;
const cartAmount = storedData.getCounts().cartCount;

const menu = document.createElement('nav');

const sections = document.createElement('ul');
Expand Down Expand Up @@ -63,10 +67,10 @@ function nav() {
search.classList.add('nav-icon', 'nav-search');
favorites.classList.add('nav-icon', 'nav-favorites');
favoritesCount.classList.add('nav-favorites-count');
favoritesCount.textContent = 0;
favoritesCount.textContent = favAmount;
cart.classList.add('nav-icon', 'nav-cart');
cartCount.classList.add('nav-cart-count');
cartCount.textContent = 0;
cartCount.textContent = cartAmount;
user.classList.add('nav-icon', 'nav-user');

menu.setAttribute('id', 'navigation');
Expand Down

0 comments on commit 4198c6a

Please sign in to comment.