refactor(DiaryView): streamline activity posting logic by consolidating group handling
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 43s
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 43s
- 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.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user