From 0fb44f0fd3c56d38c49ee2f69a25c5f9f6c3e368 Mon Sep 17 00:00:00 2001 From: Tim Aldinger Date: Wed, 30 Sep 2026 14:35:15 +0200 Subject: [PATCH] refactoring --- src/ShoppingListItem.js | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/ShoppingListItem.js b/src/ShoppingListItem.js index 367bb77..f087825 100644 --- a/src/ShoppingListItem.js +++ b/src/ShoppingListItem.js @@ -1,8 +1,8 @@ export class ShoppingListItem { - constructor(name, amount, onChange) { - this.name = name; - this.amount = amount; + constructor(itemName, itemAmount, onChange) { + this.itemName = itemName; + this.itemAmount = itemAmount; this.isDone = false; this.isEditing = false; this.remove = false; @@ -13,7 +13,7 @@ export class ShoppingListItem { render() { let li; if (this.isEditing) { - li = this.#renderEditing(); + li = this.#rendereditIng(); } else { li = this.#renderNormal() } @@ -21,20 +21,20 @@ export class ShoppingListItem { } - #renderEditing() { + #rendereditIng() { const li = document.createElement("li"); const editForm = document.createElement("form"); - const editNameField = document.createElement("input"); - const editAmountField = document.createElement("input"); + const editItemNameField = document.createElement("input"); + const editItemAmountField = document.createElement("input"); const saveButton = document.createElement("button"); const abortButton = document.createElement("button"); - editNameField.setAttribute("name", "newItemName"); - editNameField.setAttribute("value", this.name); + editItemNameField.setAttribute("name", "newItemName"); + editItemNameField.setAttribute("value", this.name); - editAmountField.setAttribute("name", "newItemAmount"); - editAmountField.setAttribute("value", this.amount); + editItemAmountField.setAttribute("itemName", "newItemAmount"); + editItemAmountField.setAttribute("value", this.amount); abortButton.textContent = "Abbrechen"; abortButton.addEventListener("click", (event) => { @@ -49,18 +49,18 @@ export class ShoppingListItem { const editFormData = Object.fromEntries(new FormData(editForm)); - if (!editFormData.newItemName && !editFormData.newItemAmount) { + if (!editFormData.newItemitemName && !editFormData.newItemitemAmount) { return; } - this.name = editFormData.newItemName; - this.amount = editFormData.newItemAmount; - this.isEditing = false; + this.itemName = editFormData.newItemName; + this.itemAmount = editFormData.newItemAmount; + this.isediting = false; this.onChange(); }); - editForm.appendChild(editNameField); - editForm.appendChild(editAmountField); + editForm.appendChild(editItemNameField); + editForm.appendChild(editItemAmountField); editForm.appendChild(saveButton); editForm.appendChild(abortButton); li.appendChild(editForm); @@ -74,6 +74,7 @@ export class ShoppingListItem { const removeButton = document.createElement("button"); const doneButton = document.createElement("input"); + doneButton.setAttribute("type", "checkbox"); doneButton.addEventListener("change", () => { this.isDone = doneButton.checked; @@ -90,7 +91,7 @@ export class ShoppingListItem { this.onChange(); }); - listContent.textContent = this.name + " " + this.amount; + listContent.textContent = this.itemName + " " + this.itemAmount; li.appendChild(doneButton); li.appendChild(listContent);