diff --git a/backend/routes/route/post.js b/backend/routes/route/post.js index a551961..54fb274 100644 --- a/backend/routes/route/post.js +++ b/backend/routes/route/post.js @@ -13,8 +13,11 @@ module.exports = async (req, res) => { const route = parseRoute(body.route); const stickers = parseStickers(body.stickers); const logo = parseString(body.logo, 16); + const provider = parseString(body.provider, 16) || 'DEFAULT'; const distance = parseNumber(body.distance, 0, 1000); + console.log('SAVING PROVIDER?', provider, body.provider); + if ((!route || route.length <= 0) && (!stickers || stickers.length <= 0)) { return res.send({ success: false, mode: 'empty' }); } @@ -26,7 +29,7 @@ module.exports = async (req, res) => { if (exists) { exists.set({ - title, route, stickers, logo, distance, updated_at: Date.now(), + title, route, stickers, logo, distance, updated_at: Date.now(), provider, }).save(); return res.send({ @@ -35,14 +38,14 @@ module.exports = async (req, res) => { } const created = await Route.create({ - _id: address, title, route, stickers, owner, logo, distance, + _id: address, title, route, stickers, owner, logo, distance, provider, }); await owner.routes.push(created); await owner.save(); return res.send({ - success: true, title, address, route, stickers + success: true, title, address, route, stickers, provider, }); }; diff --git a/src/redux/store.js b/src/redux/store.js index d73b687..dfd0421 100644 --- a/src/redux/store.js +++ b/src/redux/store.js @@ -46,6 +46,7 @@ export function configureStore() { } export const history = createBrowserHistory(); -export const historyListener = history.listen(location => { +export const historyListener = history.listen((location, action) => { + if (action === 'REPLACE') return; store.dispatch(locationChanged(location.pathname)); }); diff --git a/src/redux/user/sagas.js b/src/redux/user/sagas.js index 4774bd5..8ebfa78 100644 --- a/src/redux/user/sagas.js +++ b/src/redux/user/sagas.js @@ -18,7 +18,7 @@ import { setSaveOverwrite, setSaveSuccess, setTitle, setUser } from '$redux/user/actions'; -import { getUrlData, parseQuery, pushLoaderState, pushNetworkInitError, pushPath } from '$utils/history'; +import { getUrlData, parseQuery, pushLoaderState, pushNetworkInitError, pushPath, replacePath } from '$utils/history'; import { editor } from '$modules/Editor'; import { ACTIONS } from '$redux/user/constants'; import { MODES } from '$constants/modes'; @@ -265,13 +265,13 @@ function* clearSaga({ type }) { function* sendSaveRequestSaga({ title, address, force }) { if (editor.isEmpty) return yield put(setSaveError(TIPS.SAVE_EMPTY)); - const { route, stickers } = editor.dumpData(); + const { route, stickers, provider } = editor.dumpData(); const { logo, distance } = yield select(getState); const { id, token } = yield select(getUser); const { result, timeout, cancel } = yield race({ result: postMap({ - id, token, route, stickers, title, force, address, logo, distance, + id, token, route, stickers, title, force, address, logo, distance, provider, }), timeout: delay(10000), cancel: take(ACTIONS.RESET_SAVE_DIALOG), @@ -295,7 +295,8 @@ function* refreshUserData() { function* setSaveSuccessSaga({ address, title }) { const { id } = yield select(getUser); - pushPath(`/${address}/edit`); + replacePath(`/${address}/edit`); + yield put(setTitle(title)); yield put(setAddress(address)); diff --git a/src/utils/api.js b/src/utils/api.js index 5366b1f..ff9fb99 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -20,7 +20,7 @@ export const getStoredMap = ({ name }) => axios.get(API.GET_MAP, { }).then(result => (result && result.data && result.data.success && result.data)); export const postMap = ({ - title, address, route, stickers, id, token, force, logo, distance, + title, address, route, stickers, id, token, force, logo, distance, provider, }) => axios.post(API.POST_MAP, { title, address, @@ -31,6 +31,7 @@ export const postMap = ({ force, logo, distance, + provider, }).then(result => (result && result.data && result.data)); export const checkIframeToken = ({ viewer_id, auth_key }) => axios.get(API.IFRAME_LOGIN_VK, { diff --git a/src/utils/history.js b/src/utils/history.js index f847ec2..3585a25 100644 --- a/src/utils/history.js +++ b/src/utils/history.js @@ -1,9 +1,8 @@ import { history } from '$redux/store'; export const getPath = () => (window.location && window.location.pathname); -export const pushPath = url => { - return history.push(url); -}; +export const pushPath = url => history.push(url); +export const replacePath = url => history.replace(url); export const getUrlData = (url = getPath()) => { const [, path, mode] = url.split('/');