1
|
import { Paper } from '@mui/material'
|
2
|
import { Fragment, 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 { changeMarkerIdx } 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
|
changeMarkerIdx({
|
22
|
source: source.index,
|
23
|
destination: destination.index,
|
24
|
})
|
25
|
)
|
26
|
},
|
27
|
[dispatch]
|
28
|
)
|
29
|
|
30
|
return (
|
31
|
<Fragment>
|
32
|
{path && (
|
33
|
<Paper variant="outlined">
|
34
|
<DragDropCtxWrapper
|
35
|
items={path ?? []}
|
36
|
onDragEnd={onDragEnd}
|
37
|
/>
|
38
|
</Paper>
|
39
|
)}
|
40
|
</Fragment>
|
41
|
)
|
42
|
}
|
43
|
|
44
|
export default MapPointDraggableList
|