diff --git a/src/redux/user/actions.js b/src/redux/user/actions.js index c488a10..e1509e0 100644 --- a/src/redux/user/actions.js +++ b/src/redux/user/actions.js @@ -13,6 +13,7 @@ export const setActiveSticker = activeSticker => ({ type: ACTIONS.SET_ACTIVE_STI export const setLogo = logo => ({ type: ACTIONS.SET_LOGO, logo }); export const setTitle = title => ({ type: ACTIONS.SET_TITLE, title }); export const setAddress = address => ({ type: ACTIONS.SET_ADDRESS, address }); +export const setAddressOrigin = address_origin => ({ type: ACTIONS.SET_ADDRESS_ORIGIN, address_origin }); export const setPublic = is_public => ({ type: ACTIONS.SET_PUBLIC, is_public }); export const setSpeed = speed => ({ type: ACTIONS.SET_SPEED, speed }); diff --git a/src/redux/user/constants.js b/src/redux/user/constants.js index 6ee7a7a..ed432eb 100644 --- a/src/redux/user/constants.js +++ b/src/redux/user/constants.js @@ -13,6 +13,7 @@ export const ACTIONS = ({ SET_LOGO: 'SET_LOGO', SET_TITLE: 'SET_TITLE', SET_ADDRESS: 'SET_ADDRESS', + SET_ADDRESS_ORIGIN: 'SET_ADDRESS_ORIGIN', SET_PUBLIC: 'SET_PUBLIC', START_EDITING: 'START_EDITING', diff --git a/src/redux/user/reducer.js b/src/redux/user/reducer.js index 697bbe8..63be2ee 100644 --- a/src/redux/user/reducer.js +++ b/src/redux/user/reducer.js @@ -39,6 +39,7 @@ const setActiveSticker = (state, { activeSticker }) => ({ const setLogo = (state, { logo }) => ({ ...state, logo }); const setTitle = (state, { title }) => ({ ...state, title }); const setAddress = (state, { address }) => ({ ...state, address }); +const setAddressOrigin = (state, { address_origin }) => ({ ...state, address_origin }); const sendSaveRequest = state => ({ ...state, save_processing: true, }); const setSaveError = (state, { save_error }) => ({ @@ -169,6 +170,7 @@ const HANDLERS = ({ [ACTIONS.SET_LOGO]: setLogo, [ACTIONS.SET_TITLE]: setTitle, [ACTIONS.SET_ADDRESS]: setAddress, + [ACTIONS.SET_ADDRESS_ORIGIN]: setAddressOrigin, [ACTIONS.SET_SAVE_ERROR]: setSaveError, [ACTIONS.SET_SAVE_OVERWRITE]: setSaveOverwrite, @@ -208,6 +210,7 @@ export const INITIAL_STATE = { activeSticker: { set: null, sticker: null }, title: '', address: '', + address_origin: '', changed: false, provider: DEFAULT_PROVIDER, is_public: false, diff --git a/src/redux/user/sagas.js b/src/redux/user/sagas.js index 66794e6..3f5dcb0 100644 --- a/src/redux/user/sagas.js +++ b/src/redux/user/sagas.js @@ -17,7 +17,7 @@ import { setSaveError, setSaveOverwrite, setSaveSuccess, setTitle, searchSetTab, - setUser, setDialog, setPublic, + setUser, setDialog, setPublic, setAddressOrigin, } from '$redux/user/actions'; import { getUrlData, parseQuery, pushLoaderState, pushNetworkInitError, pushPath, replacePath } from '$utils/history'; import { editor } from '$modules/Editor'; @@ -77,7 +77,9 @@ function* startEditingSaga() { } function* stopEditingSaga() { - const { changed, editing, mode } = yield select(getState); + const { + changed, editing, mode, address_origin + } = yield select(getState); const { path } = getUrlData(); if (!editing) return; @@ -91,7 +93,7 @@ function* stopEditingSaga() { yield put(setChanged(false)); yield put(setEditing(editor.hasEmptyHistory)); // don't close editor if no previous map - yield pushPath(`/${path}/`); + yield pushPath(`/${(address_origin || path)}/`); } function* loadMapSaga(path) { @@ -115,6 +117,10 @@ function* iframeLoginVkSaga({ viewer_id, access_token, auth_key }) { function* replaceAddressIfItsBusy(destination, original) { + if (original) { + yield put(setAddressOrigin(original)); + } + pushPath(`/${destination}/edit`); } @@ -139,7 +145,9 @@ function* mapInitSaga() { if (mode && mode === 'edit') { if (map && map.owner && mode === 'edit' && map.owner.id !== id) { hideLoader(); - yield call(replaceAddressIfItsBusy, map.random_url); + yield call(replaceAddressIfItsBusy, map.random_url, map.address); + } else { + yield put(setAddressOrigin('')); } yield put(setEditing(true)); @@ -396,11 +404,13 @@ function* locationChangeSaga({ location }) { if (map && map.owner && mode === 'edit' && map.owner.id !== id) { // pushPath(`/${map.random_url}/edit`); - return yield call(replaceAddressIfItsBusy, map.random_url); + return yield call(replaceAddressIfItsBusy, map.random_url, map.address); } } else if (mode === 'edit' && editor.owner.id !== id) { // pushPath(`/${random_url}/edit`); - return yield call(replaceAddressIfItsBusy, random_url); + return yield call(replaceAddressIfItsBusy, random_url, address); + } else { + yield put(setAddressOrigin('')); } if (mode !== 'edit') {