1
|
import { Paper } from '@mui/material'
|
2
|
import { useCallback } from 'react'
|
3
|
import { DropResult } from 'react-beautiful-dnd'
|
4
|
import { useDispatch, useSelector } from 'react-redux'
|
5
|
import { RootState } from '../../redux/store'
|
6
|
import { moveMarkerToDestination } from '../trackingToolSlice'
|
7
|
import DragDropCtxWrapper from './DragDropCtxWrapper'
|
8
|
|
9
|
const MapPointDraggableList = () => {
|
10
|
const dispatch = useDispatch()
|
11
|
const path = useSelector(
|
12
|
(state: RootState) => state.trackingTool.displayedPath
|
13
|
)
|
14
|
const onDragEnd = useCallback(
|
15
|
({ destination, source }: DropResult) => {
|
16
|
if (!destination || !source || destination.index === source.index) {
|
17
|
return
|
18
|
}
|
19
|
|
20
|
dispatch(
|
21
|
moveMarkerToDestination({
|
22
|
source: source.index,
|
23
|
destination: destination.index,
|
24
|
})
|
25
|
)
|
26
|
},
|
27
|
[dispatch]
|
28
|
)
|
29
|
|
30
|
return (
|
31
|
<Paper variant="outlined">
|
32
|
<DragDropCtxWrapper items={path ?? []} onDragEnd={onDragEnd} />
|
33
|
</Paper>
|
34
|
)
|
35
|
}
|
36
|
|
37
|
export default MapPointDraggableList
|