Factor out control point location event behavior.

This commit is contained in:
Dan Albert 2022-10-07 14:14:49 -07:00 committed by Raffson
parent f0a30b5cb7
commit 6c388bd557
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99

View File

@ -4,6 +4,7 @@ import {
useClearControlPointDestinationMutation, useClearControlPointDestinationMutation,
useSetControlPointDestinationMutation, useSetControlPointDestinationMutation,
} from "../../api/liberationApi"; } from "../../api/liberationApi";
import { makeLocationMarkerEventHandlers } from "./EventHandlers";
import { import {
Icon, Icon,
LatLng, LatLng,
@ -35,14 +36,6 @@ function iconForControlPoint(cp: ControlPointModel) {
}); });
} }
function openInfoDialog(controlPoint: ControlPointModel) {
backend.post(`/qt/info/control-point/${controlPoint.id}`);
}
function openNewPackageDialog(controlPoint: ControlPointModel) {
backend.post(`/qt/create-package/control-point/${controlPoint.id}`);
}
interface ControlPointProps { interface ControlPointProps {
controlPoint: ControlPointModel; controlPoint: ControlPointModel;
} }
@ -147,6 +140,10 @@ function PrimaryMarker(props: ControlPointProps) {
); );
}); });
const locationClickHandlers = makeLocationMarkerEventHandlers(
props.controlPoint
);
return ( return (
<> <>
<Marker <Marker
@ -167,7 +164,7 @@ function PrimaryMarker(props: ControlPointProps) {
eventHandlers={{ eventHandlers={{
click: () => { click: () => {
if (!hasDestination) { if (!hasDestination) {
openInfoDialog(props.controlPoint); locationClickHandlers.click();
} }
}, },
contextmenu: () => { contextmenu: () => {
@ -176,7 +173,7 @@ function PrimaryMarker(props: ControlPointProps) {
resetDestination(); resetDestination();
}); });
} else { } else {
openNewPackageDialog(props.controlPoint); locationClickHandlers.contextmenu();
} }
}, },
drag: (event) => { drag: (event) => {
@ -261,14 +258,7 @@ function SecondaryMarker(props: SecondaryMarkerProps) {
// other markers are helpful so we want to keep them, but make sure the CP // other markers are helpful so we want to keep them, but make sure the CP
// is always the clickable thing. // is always the clickable thing.
zIndexOffset={1000} zIndexOffset={1000}
eventHandlers={{ eventHandlers={makeLocationMarkerEventHandlers(props.controlPoint)}
click: () => {
openInfoDialog(props.controlPoint);
},
contextmenu: () => {
openNewPackageDialog(props.controlPoint);
},
}}
> >
<Tooltip> <Tooltip>
<LocationTooltipText {...props} /> <LocationTooltipText {...props} />