diff --git a/src/containers/App.jsx b/src/containers/App.jsx index 2a5ee04..06184a2 100644 --- a/src/containers/App.jsx +++ b/src/containers/App.jsx @@ -26,6 +26,7 @@ export class App extends React.Component { componentDidMount() { this.authInit(); + window.editor = this.editor; } mapInit = () => { @@ -41,7 +42,7 @@ export class App extends React.Component { this.editor.stopEditing(); } }) - .catch(this.hideLoader); + .catch(this.startEmptyEditor); } else { // this.hideLoader(); this.startEmptyEditor(); @@ -50,9 +51,13 @@ export class App extends React.Component { startEmptyEditor = () => { const { user } = this.state; - if (!user || !user.random_url) return; + if (!user || !user.random_url || !user.id) return; replacePath(`/${user.random_url}/edit`); + + this.editor.owner = user.id; + this.editor.startEditing(); + this.hideLoader(); }; diff --git a/src/modules/Editor.js b/src/modules/Editor.js index bd5d49d..76b58ab 100644 --- a/src/modules/Editor.js +++ b/src/modules/Editor.js @@ -19,7 +19,7 @@ export class Editor { setLogo, }) { this.logo = DEFAULT_LOGO; - + this.owner = null; this.map = new Map({ container }); const { @@ -166,9 +166,9 @@ export class Editor { this.logo = logo; this.setLogo(logo); this.changeMode(MODES.NONE); - } + }; - setData = ({ route, stickers, format = 'old' }) => { + setData = ({ route, stickers, format = 'old', owner }) => { if (route) { this.poly.setPoints(route); } @@ -180,6 +180,11 @@ export class Editor { sticker: parseStickerStyle({ style, format }), })); } + + if (owner) { + this.owner = owner; + } + this.map.map.fitBounds(this.poly.poly.getBounds()); }; diff --git a/src/utils/api.js b/src/utils/api.js index 76d9786..ceefc7a 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -31,4 +31,4 @@ export const getStoredMap = ({ name }) => axios.get(API.GET_MAP, { name, action: 'load' } -}).then(result => (result && result.data && result.data.data)); +}).then(result => (result && result.data && result.data.data && result.data.owner && { ...result.data.data, owner: result.data.owner }));