summaryrefslogtreecommitdiff
path: root/components/ProductItem.js
diff options
context:
space:
mode:
authorLeo Goetz <dev@leogtz.de>2026-02-02 11:47:42 +0100
committerLeo Goetz <dev@leogtz.de>2026-02-02 11:47:42 +0100
commitbc09ac8989d5d7cc5e89bca7036b6010815dbee9 (patch)
treed5cc8a1f4e99910870589539e5fe86809795e314 /components/ProductItem.js
parentd5a420a8135537c9fc36f9dd81ec7c9fc0500e66 (diff)
feat: added components, proxy and finished project/courseHEADmaster
Diffstat (limited to 'components/ProductItem.js')
-rw-r--r--components/ProductItem.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/components/ProductItem.js b/components/ProductItem.js
new file mode 100644
index 0000000..ac9253b
--- /dev/null
+++ b/components/ProductItem.js
@@ -0,0 +1,30 @@
+import { addToCart } from "../services/Order.js";
+
+export default class ProductItem extends HTMLElement {
+ constructor() {
+ super();
+ }
+
+ connectedCallback() {
+ const template = document.getElementById("product-item-template");
+ const content = template.content.cloneNode(true);
+
+ this.appendChild(content);
+
+ const product = JSON.parse(this.dataset.product);
+ this.querySelector("h4").textContent = product.name;
+ this.querySelector("p.price").textContent = `$${product.price.toFixed(2)}`;
+ this.querySelector("img").src = `data/images/${product.image}`;
+ this.querySelector("a").addEventListener("click", (event) => {
+ console.log(event.target.tagName);
+ if (event.target.tagName.toLowerCase() == "button") {
+ addToCart(product.id);
+ } else {
+ app.router.go(`/product-${product.id}`);
+ }
+ event.preventDefault();
+ });
+ }
+}
+
+customElements.define("product-item", ProductItem);