summaryrefslogtreecommitdiff
path: root/components/DetailsPage.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/DetailsPage.js
parentd5a420a8135537c9fc36f9dd81ec7c9fc0500e66 (diff)
feat: added components, proxy and finished project/courseHEADmaster
Diffstat (limited to 'components/DetailsPage.js')
-rw-r--r--components/DetailsPage.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/components/DetailsPage.js b/components/DetailsPage.js
new file mode 100644
index 0000000..4f8eb87
--- /dev/null
+++ b/components/DetailsPage.js
@@ -0,0 +1,46 @@
+import { getProductById } from "../services/Menu.js";
+import { addToCart } from "../services/Order.js";
+
+export class DetailsPage extends HTMLElement {
+ constructor() {
+ super();
+
+ this.root = this.attachShadow({ mode: "open" });
+
+ const template = document.getElementById("details-page-template");
+ const content = template.content.cloneNode(true);
+ const styles = document.createElement("style");
+ this.root.appendChild(content);
+ this.root.appendChild(styles);
+
+ async function loadCSS() {
+ const request = await fetch("/components/DetailsPage.css");
+ styles.textContent = await request.text();
+ }
+ loadCSS();
+ }
+
+ async renderData() {
+ if (this.dataset.productId) {
+ this.product = await getProductById(this.dataset.productId);
+ this.root.querySelector("h2").textContent = this.product.name;
+ this.root.querySelector("img").src = `/data/images/${this.product.image}`;
+ this.root.querySelector(".description").textContent =
+ this.product.description;
+ this.root.querySelector(".price").textContent =
+ `$ ${this.product.price.toFixed(2)} ea`;
+ this.root.querySelector("button").addEventListener("click", () => {
+ addToCart(this.product.id);
+ app.router.go("/order");
+ });
+ } else {
+ alert("Invalid Product ID");
+ }
+ }
+
+ connectedCallback() {
+ this.renderData();
+ }
+}
+
+customElements.define("details-page", DetailsPage);