(event: DragEndEvent)
| 29 | const [, startTransition] = useTransition() |
| 30 | |
| 31 | function handleDragEnd(event: DragEndEvent) { |
| 32 | const { active, over } = event |
| 33 | const activeId = active.id.toString() |
| 34 | const overId = over?.id.toString() |
| 35 | if (overId == null || activeId == null) return |
| 36 | |
| 37 | function getNewArray(array: T[], activeId: string, overId: string) { |
| 38 | const oldIndex = array.findIndex(section => section.id === activeId) |
| 39 | const newIndex = array.findIndex(section => section.id === overId) |
| 40 | return arrayMove(array, oldIndex, newIndex) |
| 41 | } |
| 42 | |
| 43 | startTransition(async () => { |
| 44 | setOptimisticItems(items => getNewArray(items, activeId, overId)) |
| 45 | const actionData = await onOrderChange( |
| 46 | getNewArray(optimisticItems, activeId, overId).map(s => s.id) |
| 47 | ) |
| 48 | |
| 49 | actionToast({ actionData }) |
| 50 | }) |
| 51 | } |
| 52 | |
| 53 | return ( |
| 54 | <DndContext id={dndContextId} onDragEnd={handleDragEnd}> |
nothing calls this directly
no test coverage detected