From c4e237cfcaa4e1c88a877cabddc6a249556c2e96 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 14 Jan 2026 13:41:48 +0100 Subject: [PATCH] fix(accidentForm): optimize participant filtering and update localAccident handling - Improved availableMembers computed property to handle participant IDs more robustly, ensuring correct filtering of members. - Enhanced watch on accident to prevent unnecessary updates to localAccident, avoiding potential infinite loops. - Refined localAccident watchers to emit updates only on relevant changes to memberId and accident text, improving performance and reducing redundant emissions. --- .../src/components/AccidentFormDialog.vue | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/AccidentFormDialog.vue b/frontend/src/components/AccidentFormDialog.vue index baec230..4154a9c 100644 --- a/frontend/src/components/AccidentFormDialog.vue +++ b/frontend/src/components/AccidentFormDialog.vue @@ -86,7 +86,14 @@ export default { }, computed: { availableMembers() { - return this.members.filter(m => this.participants.indexOf(m.id) >= 0); + // participants ist ein Array von IDs, nicht von Objekten + const participantIds = Array.isArray(this.participants) + ? (this.participants.length > 0 && typeof this.participants[0] === 'object' + ? this.participants.map(p => p.id || p) + : this.participants) + : []; + const participantSet = new Set(participantIds); + return this.members.filter(m => participantSet.has(m.id)); }, isValid() { return this.localAccident.memberId && this.localAccident.accident && this.localAccident.accident.trim() !== ''; @@ -95,15 +102,20 @@ export default { watch: { accident: { handler(newVal) { - this.localAccident = { ...newVal }; + // Nur aktualisieren, wenn sich wirklich etwas geändert hat (verhindert Endlosschleife) + if (newVal && (newVal.memberId !== this.localAccident.memberId || newVal.accident !== this.localAccident.accident)) { + this.localAccident = { ...newVal }; + } }, - deep: true + immediate: true }, - localAccident: { - handler(newVal) { - this.$emit('update:accident', newVal); - }, - deep: true + 'localAccident.memberId'() { + // Emit nur bei Änderung der memberId, nicht bei jeder tiefen Änderung + this.$emit('update:accident', { ...this.localAccident }); + }, + 'localAccident.accident'() { + // Emit nur bei Änderung des accident-Textes + this.$emit('update:accident', { ...this.localAccident }); } }, methods: {