-
);
-export class RouterDialog extends React.Component {
- cancelDrawing = () => {
- this.props.editor.router.cancelDrawing();
- };
-
- submitDrawing = () => {
- this.props.editor.router.submitDrawing();
- };
-
- render() {
- const { routerPoints, editor } = this.props;
- const { cancelDrawing, submitDrawing } = this;
- return (
-
- {!routerPoints && noPoints({ cancelDrawing })}
- {routerPoints === 1 && firstPoint({ cancelDrawing })}
- {routerPoints >= 2 && draggablePoints({ cancelDrawing, submitDrawing })}
-
- );
- }
-}
+export const RouterDialog = ({ routerPoints, routerCancel, routerSubmit }: Props) => (
+
+ {!routerPoints && noPoints({ routerCancel })}
+ {routerPoints === 1 && firstPoint({ routerCancel })}
+ {routerPoints >= 2 && draggablePoints({ routerCancel, routerSubmit })}
+
+);
diff --git a/src/modules/Router.js b/src/modules/Router.js
index 63fd46f..55e2c15 100644
--- a/src/modules/Router.js
+++ b/src/modules/Router.js
@@ -2,14 +2,13 @@ import L from 'leaflet';
import Routing from 'leaflet-routing-machine/src/index';
import { CONFIG } from '$config';
import { DomMarker } from '$utils/DomMarker';
-import { MODES } from '$constants/modes';
export class Router {
- constructor({ map, lockMapClicks, setRouterPoints, changeMode, pushPolyPoints }) {
+ constructor({ map, lockMapClicks, setRouterPoints, pushPolyPoints }) {
this.waypoints = [];
this.lockMapClicks = lockMapClicks;
this.setRouterPoints = setRouterPoints;
- this.changeMode = changeMode;
+ // this.changeMode = changeMode;
this.pushPolyPoints = pushPolyPoints;
const routeLine = r => Routing.line(r, {
@@ -45,6 +44,8 @@ export class Router {
// this.router._line.on('mousedown', console.log);
}
+
+ // changeMode = value => store.dispatch(setMode(value));
//
pushWaypointOnClick = ({ latlng: { lat, lng } }) => {
const waypoints = this.router.getWaypoints().filter(({ latLng }) => !!latLng);
@@ -116,7 +117,8 @@ export class Router {
cancelDrawing = () => {
this.router.setWaypoints([]);
- this.changeMode(MODES.NONE);
+ // this.router.
+ // this.changeMode(MODES.NONE);
};
submitDrawing = () => {
@@ -125,10 +127,12 @@ export class Router {
const { coordinates } = route;
this.pushPolyPoints(coordinates);
- const waypoints = this.router.getWaypoints().filter(({ latLng }) => !!latLng);
- this.router.setWaypoints(waypoints[waypoints.length - 1]);
- // this.changeMode(MODES.POLY);
+ this.router.setWaypoints([]);
+
+ // UNCOMMENT THIS TO CONTINUE DRAWING
+ // const waypoints = this.router.getWaypoints().filter(({ latLng }) => !!latLng);
+ // this.router.setWaypoints(waypoints[waypoints.length - 1]);
};
clearAll = () => {
diff --git a/src/redux/user/actions.js b/src/redux/user/actions.js
index 6b946f1..034b8fb 100644
--- a/src/redux/user/actions.js
+++ b/src/redux/user/actions.js
@@ -16,3 +16,6 @@ export const setAddress = address => ({ type: ACTIONS.SET_ADDRESS, address });
export const startEditing = () => ({ type: ACTIONS.START_EDITING });
export const stopEditing = () => ({ type: ACTIONS.STOP_EDITING });
+
+export const routerCancel = () => ({ type: ACTIONS.ROUTER_CANCEL });
+export const routerSubmit = () => ({ type: ACTIONS.ROUTER_SUBMIT });
diff --git a/src/redux/user/constants.js b/src/redux/user/constants.js
index 031fdc7..db72493 100644
--- a/src/redux/user/constants.js
+++ b/src/redux/user/constants.js
@@ -14,4 +14,7 @@ export const ACTIONS = {
START_EDITING: 'START_EDITING',
STOP_EDITING: 'STOP_EDITING',
+
+ ROUTER_CANCEL: 'ROUTER_CANCEL',
+ ROUTER_SUBMIT: 'ROUTER_SUBMIT',
};
diff --git a/src/redux/user/sagas.js b/src/redux/user/sagas.js
index 68f1067..781b53d 100644
--- a/src/redux/user/sagas.js
+++ b/src/redux/user/sagas.js
@@ -127,6 +127,20 @@ function* setLogoSaga({ logo }) {
}
}
+function* routerCancelSaga() {
+ yield call(editor.router.cancelDrawing);
+ yield put(setMode(MODES.NONE));
+
+ return true;
+}
+
+function* routerSubmitSaga() {
+ yield call(editor.router.submitDrawing);
+ yield put(setMode(MODES.NONE));
+
+ return true;
+}
+
export function* userSaga() {
// ASYNCHRONOUS!!! :-)
@@ -139,4 +153,7 @@ export function* userSaga() {
yield takeEvery(ACTIONS.USER_LOGOUT, userLogoutSaga);
yield takeEvery(ACTIONS.SET_ACTIVE_STICKER, setActiveStickerSaga);
yield takeEvery(ACTIONS.SET_LOGO, setLogoSaga);
+
+ yield takeEvery(ACTIONS.ROUTER_CANCEL, routerCancelSaga);
+ yield takeEvery(ACTIONS.ROUTER_SUBMIT, routerSubmitSaga);
}