From 808493c06ef859c965522f946d75416c3ab00797 Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Fri, 8 May 2026 13:57:31 +0200 Subject: [PATCH] refactor(DiaryView): streamline activity posting logic by consolidating group handling - Simplified the logic for posting activities by reducing the number of API calls when a group is selected. - Updated the handling of `groupId` to ensure it is set correctly based on the selected group filter, improving code clarity and maintainability. --- frontend/src/views/DiaryView.vue | 40 +++++++++++--------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/frontend/src/views/DiaryView.vue b/frontend/src/views/DiaryView.vue index e6a3e5f4..e38a2db2 100644 --- a/frontend/src/views/DiaryView.vue +++ b/frontend/src/views/DiaryView.vue @@ -2334,33 +2334,19 @@ export default { return; } if (!this.addNewTimeblock && (this.groups || []).length > 0) { - const targetGroupIds = this.planGroupFilter !== '__all__' - ? [Number(this.planGroupFilter)] - : this.groups.map((g) => Number(g.id)).filter((id) => Number.isFinite(id)); - if (targetGroupIds.length > 0) { - for (const groupId of targetGroupIds) { - await apiClient.post(`/diary-date-activities/${this.currentClub}`, { - diaryDateId: this.date.id, - activity: this.newPlanItem.activity, - predefinedActivityId: this.newPlanItem.predefinedActivityId, - isTimeblock: false, - duration: this.newPlanItem.duration, - durationText: this.newPlanItem.durationText, - groupId, - orderId: this.trainingPlan.length - }); - } - } else { - await apiClient.post(`/diary-date-activities/${this.currentClub}`, { - diaryDateId: this.date.id, - activity: this.newPlanItem.activity, - predefinedActivityId: this.newPlanItem.predefinedActivityId, - isTimeblock: false, - duration: this.newPlanItem.duration, - durationText: this.newPlanItem.durationText, - orderId: this.trainingPlan.length - }); - } + const selectedGroupId = this.planGroupFilter !== '__all__' + ? Number(this.planGroupFilter) + : null; + await apiClient.post(`/diary-date-activities/${this.currentClub}`, { + diaryDateId: this.date.id, + activity: this.newPlanItem.activity, + predefinedActivityId: this.newPlanItem.predefinedActivityId, + isTimeblock: false, + duration: this.newPlanItem.duration, + durationText: this.newPlanItem.durationText, + groupId: Number.isFinite(selectedGroupId) ? selectedGroupId : null, + orderId: this.trainingPlan.length + }); } else { await apiClient.post(`/diary-date-activities/${this.currentClub}`, { diaryDateId: this.date.id,