Fix: Event-Delegation für Tee-Karten-Buttons statt individueller Event-Listener

- Ein Event-Listener am Container statt mehrfacher Listener an jedem Button
- Funktioniert für alle aktuellen und zukünftigen Buttons
- Keine Probleme mit mehrfachen Event-Listenern
- Einfacherer, robusterer Code

Co-authored-by: trevor1969 <trevor1969@users.noreply.github.com>
This commit is contained in:
Vibe Nuage Agent
2026-06-06 11:37:29 +00:00
parent b2f632c07f
commit 23c83ef4d1

43
app.js
View File

@ -759,6 +759,28 @@ class TeeTracker {
this.switchTab(button.dataset.tab); this.switchTab(button.dataset.tab);
}); });
}); });
// Event delegation for tea card buttons (edit and delete)
const teasList = document.getElementById('teas-list');
if (teasList) {
teasList.addEventListener('click', (e) => {
// Edit button
const editBtn = e.target.closest('.tea-edit-btn');
if (editBtn) {
const teaId = editBtn.dataset.teaId;
if (teaId) this.editTea(teaId);
return;
}
// Delete button
const deleteBtn = e.target.closest('.tea-delete-btn');
if (deleteBtn) {
const teaId = deleteBtn.dataset.teaId;
if (teaId) this.showDeleteTeaConfirm(teaId);
return;
}
});
}
// Add tea button // Add tea button
const addTeaBtn = document.getElementById('add-tea-btn'); const addTeaBtn = document.getElementById('add-tea-btn');
@ -1394,27 +1416,6 @@ class TeeTracker {
</div> </div>
</div> </div>
`).join(''); `).join('');
// Add event listeners to all edit and delete buttons
this.setupTeaCardEventListeners();
}
setupTeaCardEventListeners() {
// Edit buttons
document.querySelectorAll('.tea-edit-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const teaId = e.target.closest('.tea-edit-btn').dataset.teaId;
if (teaId) this.editTea(teaId);
});
});
// Delete buttons
document.querySelectorAll('.tea-delete-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
const teaId = e.target.closest('.tea-delete-btn').dataset.teaId;
if (teaId) this.showDeleteTeaConfirm(teaId);
});
});
} }
// ============================================ // ============================================