fix: add action list
This commit is contained in:
57
js/app.js
57
js/app.js
@@ -3,6 +3,9 @@
|
||||
* Imports and registers all web components
|
||||
*/
|
||||
|
||||
// Import cart store (must be first to set up window.cartStore)
|
||||
import cart from "./store/cart.js";
|
||||
|
||||
// Import all components
|
||||
import "./components/site-header.js";
|
||||
import "./components/top-bar.js";
|
||||
@@ -20,6 +23,9 @@ import "./components/cta-button.js";
|
||||
import "./components/category-card.js";
|
||||
import "./components/newsletter-signup.js";
|
||||
import "./components/book-details.js";
|
||||
import "./components/icon-cta-button.js";
|
||||
import "./components/icon-link-button.js";
|
||||
import "./components/action-links-list.js";
|
||||
|
||||
// Import icon components
|
||||
import "./icons/menu-icon.js";
|
||||
@@ -30,7 +36,56 @@ import "./icons/book-open-icon.js";
|
||||
import "./icons/clipboard-icon.js";
|
||||
import "./icons/chevron-down-icon.js";
|
||||
|
||||
// App initialization (if needed)
|
||||
// App initialization
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
console.log("BookStore app initialized");
|
||||
|
||||
// Initialize cart badge on page load
|
||||
const count = cart.getItemCount();
|
||||
if (count > 0) {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent("cart-updated", {
|
||||
detail: {
|
||||
items: cart.getItems(),
|
||||
count: count,
|
||||
total: cart.getTotal(),
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// Listen for add-to-cart events from book-card and book-details components
|
||||
document.addEventListener("add-to-cart", (event) => {
|
||||
const { title, author, price, type, image } = event.detail || {};
|
||||
|
||||
if (title) {
|
||||
cart.addItem({
|
||||
title,
|
||||
author: author || "",
|
||||
price: price || "€ 0,00",
|
||||
type: type || "physical",
|
||||
image: image || "",
|
||||
});
|
||||
|
||||
// Optional: Show feedback to user
|
||||
console.log(`Added "${title}" to cart`);
|
||||
}
|
||||
});
|
||||
|
||||
// Listen for buy-ebook events from book-details component
|
||||
document.addEventListener("buy-ebook", (event) => {
|
||||
const { title } = event.detail || {};
|
||||
|
||||
if (title) {
|
||||
cart.addItem({
|
||||
title,
|
||||
author: "",
|
||||
price: "€ 0,00", // eBook price would come from component
|
||||
type: "ebook",
|
||||
image: "",
|
||||
});
|
||||
|
||||
console.log(`Added eBook "${title}" to cart`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user