diff --git a/src/redux/map/actions.ts b/src/redux/map/actions.ts index 31d42cb..e02e400 100644 --- a/src/redux/map/actions.ts +++ b/src/redux/map/actions.ts @@ -18,6 +18,11 @@ export const mapSetRoute = (route: IMapReducer['route']) => ({ route, }); +export const mapSetStickers = (stickers: IStickerDump[]) => ({ + type: MAP_ACTIONS.SET_STICKERS, + stickers, +}); + export const mapSetSticker = (index: number, sticker: IStickerDump) => ({ type: MAP_ACTIONS.SET_STICKER, index, diff --git a/src/redux/map/constants.ts b/src/redux/map/constants.ts index c7ffed4..253eeb9 100644 --- a/src/redux/map/constants.ts +++ b/src/redux/map/constants.ts @@ -14,6 +14,7 @@ export const MAP_ACTIONS = { ADD_STICKER: `${P}-ADD_STICKER`, SET_STICKER: `${P}-SET_STICKER`, + SET_STICKERS: `${P}-SET_STICKERS`, DROP_STICKER: `${P}-DROP_STICKER`, MAP_CLICKED: `${P}-MAP_CLICKED` diff --git a/src/redux/map/handlers.ts b/src/redux/map/handlers.ts index ce4daf6..144ef83 100644 --- a/src/redux/map/handlers.ts +++ b/src/redux/map/handlers.ts @@ -13,6 +13,7 @@ import { mapSetPublic, mapSetLogo, mapSetAddressOrigin, + mapSetStickers, } from './actions'; const setMap = (state: IMapReducer, { map }: ReturnType): IMapReducer => ({ @@ -33,6 +34,14 @@ const setRoute = (state: IMapReducer, { route }: ReturnType) route, }); +const setStickers = ( + state: IMapReducer, + { stickers }: ReturnType +): IMapReducer => ({ + ...state, + stickers, +}); + const setSticker = ( state: IMapReducer, { sticker, index }: ReturnType @@ -97,6 +106,7 @@ export const MAP_HANDLERS = { [MAP_ACTIONS.SET_PROVIDER]: setProvider, [MAP_ACTIONS.SET_ROUTE]: setRoute, [MAP_ACTIONS.SET_STICKER]: setSticker, + [MAP_ACTIONS.SET_STICKERS]: setStickers, [MAP_ACTIONS.DROP_STICKER]: dropSticker, [MAP_ACTIONS.ADD_STICKER]: addSticker, [MAP_ACTIONS.SET_TITLE]: setTitle, diff --git a/src/redux/map/sagas.ts b/src/redux/map/sagas.ts index 849fb5e..8deecd2 100644 --- a/src/redux/map/sagas.ts +++ b/src/redux/map/sagas.ts @@ -16,6 +16,8 @@ import { mapSet, mapSetTitle, mapSetAddressOrigin, + mapSetRoute, + mapSetStickers, } from './actions'; import { selectUser, selectUserUser } from '~/redux/user/selectors'; import { MODES } from '~/constants/modes'; @@ -32,7 +34,7 @@ import { import { pushLoaderState, getUrlData, pushPath } from '~/utils/history'; import { getStoredMap, postMap } from '~/utils/api'; import { Unwrap } from '~/utils/middleware'; -import { selectMap, selectMapProvider } from './selectors'; +import { selectMap, selectMapProvider, selectMapRoute, selectMapStickers } from './selectors'; import { TIPS } from '~/constants/tips'; import { delay } from 'redux-saga'; import { setReadySaga } from '../editor/sagas'; @@ -169,29 +171,26 @@ function* startEditingSaga() { } function* clearPolySaga() { - yield put( - mapSet({ - route: [], - }) - ); + const route: ReturnType = yield select(selectMapRoute) + if (!route.length) return; + yield put(mapSetRoute([])); } function* clearStickersSaga() { - yield put( - mapSet({ - stickers: [], - }) - ); + const stickers: ReturnType = yield select(selectMapStickers) + if (!stickers.length) return; + yield put(mapSetStickers([])); } function* clearAllSaga() { + const route: ReturnType = yield select(selectMapRoute) + const stickers: ReturnType = yield select(selectMapStickers) + + if (!stickers.length && !route.length) return; + yield put(editorSetChanged(false)); - yield put( - mapSet({ - route: [], - stickers: [], - }) - ); + yield put(mapSetRoute([])); + yield put(mapSetStickers([])); } function* clearSaga({ type }) { @@ -321,15 +320,16 @@ function* setChanged() { } export function* mapSaga() { - yield takeEvery([MAP_ACTIONS.SET_ROUTE, MAP_ACTIONS.SET_STICKER], setChanged); + yield takeEvery( + [MAP_ACTIONS.SET_ROUTE, MAP_ACTIONS.SET_STICKER, MAP_ACTIONS.SET_STICKERS], + setChanged + ); - // TODO: setChanged on set route, logo, provider, stickers yield takeEvery(EDITOR_ACTIONS.START_EDITING, startEditingSaga); yield takeEvery(EDITOR_ACTIONS.SET_ACTIVE_STICKER, setActiveStickerSaga); yield takeEvery(MAP_ACTIONS.MAP_CLICKED, onMapClick); yield takeEvery(MAP_ACTIONS.SET_TITLE, setTitleSaga); yield takeLatest(EDITOR_ACTIONS.SEND_SAVE_REQUEST, sendSaveRequestSaga); - // yield takeLatest(EDITOR_ACTIONS.SET_SAVE_SUCCESS, setSaveSuccessSaga); yield takeEvery( [