From 25d9b1d2dfbd619cdf72ee3737c66ffcd4224cff Mon Sep 17 00:00:00 2001 From: muerwre Date: Tue, 4 Sep 2018 10:45:33 +0700 Subject: [PATCH] possibly fixed editor initialData --- src/components/save/SaveDialog.jsx | 6 +++++ src/containers/App.jsx | 5 +++- src/modules/Editor.js | 38 +++++++++++++++++------------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/components/save/SaveDialog.jsx b/src/components/save/SaveDialog.jsx index 894ec58..6c94c4f 100644 --- a/src/components/save/SaveDialog.jsx +++ b/src/components/save/SaveDialog.jsx @@ -60,6 +60,12 @@ export class SaveDialog extends React.Component { setSuccess = ({ address, description }) => { pushPath(`/${address}/edit`); + console.log('addr?', address); + this.props.editor.setAddress(address); + this.props.editor.owner = this.props.user.id; + + this.props.editor.setInitialData(); + this.setState({ error: description, finished: true, sending: true, overwriting: false }); diff --git a/src/containers/App.jsx b/src/containers/App.jsx index e82ede8..4fae52b 100644 --- a/src/containers/App.jsx +++ b/src/containers/App.jsx @@ -67,7 +67,10 @@ export class App extends React.Component { }; setTitle = title => this.setState({ title }); - setAddress = address => this.setState({ address }); + setAddress = address => { + console.log('SAT', address); + this.setState({ address }); + }; getTitle = () => this.state.title; diff --git a/src/modules/Editor.js b/src/modules/Editor.js index 31826c6..3c4d00b 100644 --- a/src/modules/Editor.js +++ b/src/modules/Editor.js @@ -190,7 +190,9 @@ export class Editor { setData = ({ route, stickers, version = 1, owner, title, address }) => { this.setTitle(title || ''); - this.setAddress(address || ''); + const { id } = this.getUser(); + + if (address && id && owner && id === owner) this.setAddress(address); if (route) { this.poly.setPoints(route); @@ -215,21 +217,9 @@ export class Editor { if (Object.values(bounds)) this.map.map.fitBounds(bounds); }; - startEditing = () => { + setInitialData = () => { const { path } = getUrlData(); - const { random_url, id } = this.getUser(); - - // console.log('ID', id, this.owner); - - const url = (this.owner && this.owner === id) ? path : random_url; - - pushPath(`/${url}/edit`); - - if (this.poly.latlngs && this.poly.latlngs.length > 1) this.poly.poly.enableEdit(); - - this.stickers.startEditing(); - this.setEditing(true); - + const { id } = this.getUser(); const { route, stickers } = this.dumpData(); this.initialData = { @@ -241,6 +231,22 @@ export class Editor { route, stickers, }; + }; + + startEditing = () => { + const { path } = getUrlData(); + const { random_url, id } = this.getUser(); + + this.setInitialData(); + + const url = (this.owner && this.owner === id) ? path : random_url; + + pushPath(`/${url}/edit`); + + if (this.poly.latlngs && this.poly.latlngs.length > 1) this.poly.poly.enableEdit(); + + this.stickers.startEditing(); + this.setEditing(true); console.log(this.initialData); }; @@ -284,6 +290,6 @@ export class Editor { hasEmptyHistory = () => { const { route, stickers } = this.initialData; - return !(route && route.length >= 1 && stickers && stickers.length > 0); + return (!route || route.length < 1) && (!stickers || stickers.length <= 0); } }