diff --git a/src/containers/map/Map/index.tsx b/src/containers/map/Map/index.tsx index faa91db..f775db1 100644 --- a/src/containers/map/Map/index.tsx +++ b/src/containers/map/Map/index.tsx @@ -13,13 +13,15 @@ import { Stickers } from '~/containers/map/Stickers'; import { KmMarks } from '~/containers/map/KmMarks'; import 'leaflet/dist/leaflet.css'; -import { selectEditorEditing } from '~/redux/editor/selectors'; +import { selectEditorEditing, selectEditorMode } from '~/redux/editor/selectors'; +import { MODES } from '~/constants/modes'; const mapStateToProps = state => ({ provider: selectMapProvider(state), route: selectMapRoute(state), stickers: selectMapStickers(state), editing: selectEditorEditing(state), + mode: selectEditorMode(state), }); const mapDispatchToProps = { @@ -37,6 +39,7 @@ const MapUnconnected: React.FC = ({ provider, stickers, editing, + mode, mapClicked, mapSetSticker, @@ -44,11 +47,11 @@ const MapUnconnected: React.FC = ({ }) => { const onClick = React.useCallback( event => { - if (!MainMap.clickable) return; + if (!MainMap.clickable || mode === MODES.NONE) return; mapClicked(event.latlng); }, - [mapClicked] + [mapClicked, mode] ); React.useEffect(() => { diff --git a/src/redux/editor/sagas.ts b/src/redux/editor/sagas.ts index 4d58586..7023438 100644 --- a/src/redux/editor/sagas.ts +++ b/src/redux/editor/sagas.ts @@ -5,7 +5,6 @@ import { simplify } from '~/utils/simplify'; import { editorHideRenderer, editorSetChanged, - editorSetEditing, editorSetMode, editorSetReady, editorSetRenderer, @@ -40,7 +39,7 @@ import { import { selectMap, selectMapRoute } from '../map/selectors'; import { selectUser } from '../user/selectors'; import { LOGOS } from '~/constants/logos'; -import { loadMapSaga, startEmptyEditorSaga, loadMapFromPath } from '../map/sagas'; +import { loadMapFromPath } from '../map/sagas'; import { mapClicked, mapSetRoute } from '../map/actions'; import { MAP_ACTIONS } from '../map/constants'; import { OsrmRouter } from '~/utils/osrm'; @@ -56,12 +55,10 @@ const hideLoader = () => { }; function* stopEditingSaga() { - const { changed, editing, mode }: ReturnType = yield select(selectEditor); + const { changed, mode }: ReturnType = yield select(selectEditor); const { address_origin }: ReturnType = yield select(selectMap); const { path } = getUrlData(); - // if (!editing) return; - if (changed && mode !== MODES.CONFIRM_CANCEL) { yield put(editorSetMode(MODES.CONFIRM_CANCEL)); return; diff --git a/src/redux/map/sagas.ts b/src/redux/map/sagas.ts index 65df3bd..849fb5e 100644 --- a/src/redux/map/sagas.ts +++ b/src/redux/map/sagas.ts @@ -313,7 +313,16 @@ function* sendSaveRequestSaga({ ); } +function* setChanged() { + const { changed } = yield select(selectEditor); + if (changed) return; + + yield put(editorSetChanged(true)); +} + export function* mapSaga() { + yield takeEvery([MAP_ACTIONS.SET_ROUTE, MAP_ACTIONS.SET_STICKER], setChanged); + // TODO: setChanged on set route, logo, provider, stickers yield takeEvery(EDITOR_ACTIONS.START_EDITING, startEditingSaga); yield takeEvery(EDITOR_ACTIONS.SET_ACTIVE_STICKER, setActiveStickerSaga);