From d95f51bd3bc532e675db87bb79fe1882eb11855f Mon Sep 17 00:00:00 2001 From: muerwre Date: Mon, 10 Dec 2018 10:48:08 +0700 Subject: [PATCH] import: added hash to url translation for old maps support editor: fixed setProvider --- src/modules/Editor.js | 19 ++++++++++++------- src/redux/user/sagas.js | 15 ++++++++++++++- src/utils/history.js | 4 ++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/modules/Editor.js b/src/modules/Editor.js index 7b50233..c5a7e7a 100644 --- a/src/modules/Editor.js +++ b/src/modules/Editor.js @@ -10,10 +10,13 @@ import { getUrlData } from '$utils/history'; import { store } from '$redux/store'; import { resetSaveDialog, - setActiveSticker, setAddress, + setActiveSticker, + setAddress, setChanged, - setDistance, setLogo, + setDistance, + setLogo, setMode, + setProvider, setRouterPoints, setTitle, } from '$redux/user/actions'; @@ -325,12 +328,14 @@ export class Editor { provider: this.provider, }); - setProvider = provider => { - if (provider === this.provider) return; + // setProvider = provider => { + // if (provider === this.provider) return; + // + // this.provider = provider; + // this.map.setProvider(provider); + // }; - this.provider = provider; - this.map.setProvider(provider); - }; + setProvider = provider => store.dispatch(setProvider(provider)); get isEmpty() { const { route, stickers } = this.dumpData(); diff --git a/src/redux/user/sagas.js b/src/redux/user/sagas.js index c959584..1b4123e 100644 --- a/src/redux/user/sagas.js +++ b/src/redux/user/sagas.js @@ -102,8 +102,19 @@ function* loadMapSaga(path) { } function* mapInitSaga() { + const { hash } = getUrlData(); + + if (hash && /^#map/.test(hash)) { + const [, newUrl] = hash.match(/^#map[:/?!](.*)$/); + + if (newUrl) { + yield pushPath(`/${newUrl}`); + } + } + const { path, mode } = getUrlData(); + if (path) { const map = yield call(loadMapSaga, path); // const map = yield call(getStoredMap, { name: path }); @@ -326,7 +337,9 @@ function* cropAShotSaga(params) { } function setProviderSaga({ provider }) { - editor.setProvider(provider); + // editor.setProvider(provider); + editor.provider = provider; + editor.map.setProvider(provider); return put(setMode(MODES.NONE)); } diff --git a/src/utils/history.js b/src/utils/history.js index 7513426..5aefde7 100644 --- a/src/utils/history.js +++ b/src/utils/history.js @@ -8,7 +8,7 @@ export const pushPath = url => { export const getUrlData = (url = getPath()) => { const [, path, mode] = url.split('/'); - const { host } = window.location; + const { host, hash } = window.location; - return { path, mode, host }; + return { path, mode, host, hash }; };