feat(DiaryView): enhance drag-and-drop functionality for training plan items
- Added a new class for sortable rows in the training plan table, improving the drag-and-drop experience. - Updated the sortable initialization to target the new class, ensuring proper item handling during reordering. - Implemented a check in the drag end event to prevent errors when no item is moved, enhancing stability.
This commit is contained in:
@@ -483,7 +483,7 @@
|
||||
</thead>
|
||||
<tbody ref="sortableList">
|
||||
<template v-for="(item, index) in trainingPlan" :key="item.id">
|
||||
<tr :class="{ 'plan-timeblock-row': item.isTimeblock }">
|
||||
<tr :class="{ 'plan-timeblock-row': item.isTimeblock }" class="plan-sortable-row" :data-plan-id="item.id">
|
||||
<td class="drag-handle" style="cursor: move;">☰</td> <!-- Drag-Handle -->
|
||||
<td>{{ formatDisplayTime(item.startTime) }}</td>
|
||||
<td>
|
||||
@@ -1478,6 +1478,7 @@ export default {
|
||||
initializeSortable() {
|
||||
const el = this.$refs.sortableList;
|
||||
Sortable.create(el, {
|
||||
draggable: '.plan-sortable-row',
|
||||
handle: ".drag-handle",
|
||||
onEnd: this.onDragEnd,
|
||||
});
|
||||
@@ -2242,6 +2243,9 @@ export default {
|
||||
},
|
||||
async onDragEnd(evt) {
|
||||
const movedItem = this.trainingPlan[evt.oldIndex];
|
||||
if (!movedItem) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await apiClient.put(`/diary-date-activities/${this.currentClub}/${movedItem.id}/order`, {
|
||||
orderId: evt.newIndex
|
||||
|
||||
Reference in New Issue
Block a user