diff --git a/src/templates/index.html b/src/templates/index.html
index fe8e85d..0d96248 100644
--- a/src/templates/index.html
+++ b/src/templates/index.html
@@ -117,43 +117,34 @@ function updateRowWithNewData(row, weight, nutritionData) {
}
function removeSelectedRow() {
- const table = document.getElementById('nutrition-table');
- let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
+ const table = document.getElementById('nutrition-table');
+ Array.from(table.rows).forEach(row => {
+ if (row.classList.contains('selected')) {
+ let rowData = {
+ food: row.cells[0].innerText,
+ weight: row.cells[1].innerText,
+ // Weitere Daten bei Bedarf
+ };
- // Durchgehen aller Zeilen, um zu prüfen, ob sie ausgewählt sind
- Array.from(table.rows).forEach(row => {
- if (row.classList.contains('selected')) {
- // Annahme: Jede Zeile hat ein data-id Attribut, das dem Index im entries Array entspricht
- const entryIndex = row.getAttribute('data-id');
+ // Entfernen des Eintrags aus dem lokalen Speicher
+ removeEntryFromLocalStorage(rowData);
- // Entfernen des Eintrags aus dem Array, falls vorhanden
- if (entryIndex !== null) {
- entries.splice(entryIndex, 1);
- // Notwendig, um die IDs zu aktualisieren, da das Array jetzt kürzer ist
- updateDataIds();
- }
-
- // Visuelles Entfernen der Zeile aus der Tabelle
- row.parentNode.removeChild(row);
+ table.deleteRow(row.rowIndex);
+ }
+ });
+ updateRemoveButtonState();
+ updateTotalNutrition();
}
- });
-
- // Aktualisieren des localStorage mit dem neuen Array ohne den entfernten Eintrag
- localStorage.setItem('nutritionEntries', JSON.stringify(entries));
-
- // Funktion, um die data-id Attribute der verbleibenden Zeilen zu aktualisieren
- function updateDataIds() {
- Array.from(table.rows).slice(1).forEach((row, index) => {
- row.setAttribute('data-id', index.toString());
- });
- }
-}
function removeEntryFromLocalStorage(rowData) {
- let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
- entries = entries.filter(entry => entry.food !== rowData.food || entry.weight !== rowData.weight);
- localStorage.setItem('nutritionEntries', JSON.stringify(entries));
- }
+ let entries = JSON.parse(localStorage.getItem('nutritionEntries')) || [];
+ // Konvertieren von rowData.weight in eine Zahl, um eine korrekte Vergleichsbasis zu schaffen
+ const weightToCompare = parseFloat(rowData.weight);
+ // Verwendung einer strikten Gleichheitsprüfung für beide Werte
+ entries = entries.filter(entry => entry.food !== rowData.food || parseFloat(entry.weight) !== weightToCompare);
+ localStorage.setItem('nutritionEntries', JSON.stringify(entries));
+}
+
function updateRemoveButtonState() {
const selectedRows = document.querySelectorAll('#nutrition-table .selected').length;