Skip to content

Commit

Permalink
#41 Using filter instead of switch
Browse files Browse the repository at this point in the history
Works for product details
- Add the back btn to go to sub categories & sup category
  • Loading branch information
Chrstjan committed Mar 4, 2024
1 parent 6740127 commit a6be6a8
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ function categoryCallback(clickedSubCategory) {
}

function breadcrumbCallback(breadcrumb) {
let breadcrumbArray = [];
const filteredProducts = allProducts.filter(product => product.category === breadcrumb);
buildProductCard(filteredProducts);
//#region old hardcoded code
/*let breadcrumbArray = [];
allProducts.forEach((product) => {
if (product.category == breadcrumb) {
switch (breadcrumb) {
Expand All @@ -275,11 +278,22 @@ function breadcrumbCallback(breadcrumb) {
break;
}
//case...
case "fragrances": {
breadcrumbArray.push(product);
buildProductCard(breadcrumbArray);
break;
}
case "skincare": {
breadcrumbArray.push(product);
buildProductCard(breadcrumbArray);
break;
}
}
}
});
console.log(breadcrumbArray);
console.log(breadcrumbArray); */
//#endregion old code
}

function retrieveLocalStorage() {
Expand Down

0 comments on commit a6be6a8

Please sign in to comment.