fix(DiaryView): improve drag-and-drop item reordering logic
- Updated the drag-and-drop functionality to correctly handle item indices during reordering, ensuring accurate updates to the training plan. - Enhanced error handling by loading the training plan after a successful reorder, improving user experience and stability.
This commit is contained in:
@@ -2242,15 +2242,17 @@ export default {
|
||||
}
|
||||
},
|
||||
async onDragEnd(evt) {
|
||||
const movedItem = this.trainingPlan[evt.oldIndex];
|
||||
const oldIndex = Number.isInteger(evt.oldDraggableIndex) ? evt.oldDraggableIndex : evt.oldIndex;
|
||||
const newIndex = Number.isInteger(evt.newDraggableIndex) ? evt.newDraggableIndex : evt.newIndex;
|
||||
const movedItem = this.trainingPlan[oldIndex];
|
||||
if (!movedItem) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await apiClient.put(`/diary-date-activities/${this.currentClub}/${movedItem.id}/order`, {
|
||||
orderId: evt.newIndex
|
||||
orderId: newIndex + 1
|
||||
});
|
||||
this.recalculateTimes();
|
||||
await this.loadTrainingPlan();
|
||||
} catch (error) {
|
||||
this.showInfo(this.$t('messages.error'), this.$t('diary.errorOccurred'), '', 'error');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user