|
|
|
@ -1,66 +1,18 @@ |
|
|
|
|
import { useCallback, useReducer } from 'preact/hooks'; |
|
|
|
|
import { Coordinates } from '../shared/types'; |
|
|
|
|
import { useMemo, useReducer } from 'preact/hooks'; |
|
|
|
|
import { ExportComponent } from './export'; |
|
|
|
|
import { MapComponent } from './map'; |
|
|
|
|
import { MarkersComponent } from './markers'; |
|
|
|
|
import { ReorderMarkersParams } from './types'; |
|
|
|
|
import { createChangeStateMethods, markersReducer } from './reducer'; |
|
|
|
|
|
|
|
|
|
import './style.css'; |
|
|
|
|
import { markersReducer } from './reducer'; |
|
|
|
|
|
|
|
|
|
export const RoutePlanner = () => { |
|
|
|
|
const [markers, dispatchMarkers] = useReducer(markersReducer, []); |
|
|
|
|
|
|
|
|
|
const reorderMarkers = useCallback( |
|
|
|
|
({ oldIndex, newIndex }: ReorderMarkersParams): void => |
|
|
|
|
dispatchMarkers({ |
|
|
|
|
type: 'reorder', |
|
|
|
|
data: { oldIndex, newIndex }, |
|
|
|
|
}), |
|
|
|
|
[], |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const moveMarkerUp = useCallback( |
|
|
|
|
(key: string) => |
|
|
|
|
dispatchMarkers({ |
|
|
|
|
type: 'moveUp', |
|
|
|
|
data: { key }, |
|
|
|
|
}), |
|
|
|
|
[], |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const moveMarkerDown = useCallback( |
|
|
|
|
(key: string) => |
|
|
|
|
dispatchMarkers({ |
|
|
|
|
type: 'moveDown', |
|
|
|
|
data: { key }, |
|
|
|
|
}), |
|
|
|
|
[], |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const removeMarker = useCallback( |
|
|
|
|
(key: string) => |
|
|
|
|
dispatchMarkers({ |
|
|
|
|
type: 'remove', |
|
|
|
|
data: { key }, |
|
|
|
|
}), |
|
|
|
|
const { reorderMarkers, addMarker } = useMemo( |
|
|
|
|
() => createChangeStateMethods(dispatchMarkers), |
|
|
|
|
[], |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const addMarker = useCallback( |
|
|
|
|
(coordinates: Coordinates) => |
|
|
|
|
dispatchMarkers({ |
|
|
|
|
type: 'add', |
|
|
|
|
data: { |
|
|
|
|
coordinates, |
|
|
|
|
moveUp: moveMarkerUp, |
|
|
|
|
moveDown: moveMarkerDown, |
|
|
|
|
remove: removeMarker, |
|
|
|
|
}, |
|
|
|
|
}), |
|
|
|
|
[moveMarkerUp, moveMarkerDown, removeMarker], |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<section class="route-planner"> |
|
|
|
|
<section class="markers"> |
|
|
|
|