Skip to content

Commit f87c5b4

Browse files
committed
fix(typescript): fix vue draggable typescript issues
Signed-off-by: Zacharias Fragkiadakis <[email protected]>
1 parent fd8a3e4 commit f87c5b4

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

components/Column.vue

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script setup lang="ts">
2-
import { VueDraggable } from 'vue-draggable-plus'
2+
import { type SortableEvent, VueDraggable } from 'vue-draggable-plus'
33
import type { Task } from '../types/tasks'
4-
import type { VueDraggableEvent } from '~/types/vue-draggable-plus'
54
import { doneTaskStatuses } from '~/constants/tasks'
65
76
const props = defineProps<{
@@ -29,18 +28,23 @@ watchEffect(() => {
2928
}
3029
})
3130
32-
function handleMoveTask(event: VueDraggableEvent) {
33-
const { id, kind } = event.item.dataset
34-
const { column } = event.to.dataset
31+
function handleMoveTask(event: SortableEvent) {
32+
const { oldIndex, newIndex, item, to } = event
33+
const { id, kind } = item.dataset
34+
const { column } = to.dataset
35+
if (!id || !kind || !column || oldIndex === undefined || newIndex === undefined) {
36+
throw new Error('Invalid task move event')
37+
}
38+
3539
const task = props.tasks.find((task) => task.rpb.kind === kind && task.id === id)
36-
if (!task || !column || (task.rpb.column === column && event.oldIndex === event.newIndex)) {
40+
if (!task || !column || (task.rpb.column === column && oldIndex === newIndex)) {
3741
return
3842
}
3943
4044
tasks.moveTask({
4145
task,
4246
column,
43-
index: event.newIndex,
47+
index: newIndex,
4448
})
4549
}
4650

pages/[node]/[rid].vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script setup lang="ts">
2-
import { VueDraggable } from 'vue-draggable-plus'
2+
import { type SortableEvent, VueDraggable } from 'vue-draggable-plus'
33
import { elementIds } from '~/constants/elements'
4-
import type { VueDraggableEvent } from '~/types/vue-draggable-plus'
54
65
const auth = useAuthStore()
76
const tasks = useTasksStore()
@@ -15,7 +14,11 @@ watchEffect(() => {
1514
}
1615
})
1716
18-
function handleMoveColumn({ oldIndex, newIndex }: VueDraggableEvent) {
17+
function handleMoveColumn({ oldIndex, newIndex }: SortableEvent) {
18+
if (!oldIndex || !newIndex) {
19+
throw new Error('Invalid column move event')
20+
}
21+
1922
const column = board.state.columns[oldIndex]
2023
if (!column) {
2124
return

0 commit comments

Comments
 (0)