mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 19:16:41 +07:00
editor cancels to initial state
This commit is contained in:
parent
bed9ea6948
commit
fce88cac29
3 changed files with 50 additions and 4 deletions
|
@ -25,7 +25,7 @@ export class EditorPanel extends React.PureComponent {
|
||||||
|
|
||||||
stopEditing = () => {
|
stopEditing = () => {
|
||||||
if (!this.props.changed){
|
if (!this.props.changed){
|
||||||
this.props.editor.stopEditing();
|
this.props.editor.cancelEditing();
|
||||||
} else {
|
} else {
|
||||||
this.props.editor.changeMode(MODES.CONFIRM_CANCEL);
|
this.props.editor.changeMode(MODES.CONFIRM_CANCEL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,8 @@ export class App extends React.Component {
|
||||||
setTitle = title => this.setState({ title });
|
setTitle = title => this.setState({ title });
|
||||||
setAddress = address => this.setState({ address });
|
setAddress = address => this.setState({ address });
|
||||||
|
|
||||||
|
getTitle = () => this.state.title;
|
||||||
|
|
||||||
setDataOnLoad = data => {
|
setDataOnLoad = data => {
|
||||||
this.clearChanged();
|
this.clearChanged();
|
||||||
this.editor.setData(data);
|
this.editor.setData(data);
|
||||||
|
@ -133,6 +135,7 @@ export class App extends React.Component {
|
||||||
getUser: this.getUser,
|
getUser: this.getUser,
|
||||||
triggerOnChange: this.triggerOnChange,
|
triggerOnChange: this.triggerOnChange,
|
||||||
clearChanged: this.clearChanged,
|
clearChanged: this.clearChanged,
|
||||||
|
getTitle: this.getTitle,
|
||||||
});
|
});
|
||||||
|
|
||||||
authInit = () => {
|
authInit = () => {
|
||||||
|
|
|
@ -24,10 +24,12 @@ export class Editor {
|
||||||
getUser,
|
getUser,
|
||||||
triggerOnChange,
|
triggerOnChange,
|
||||||
clearChanged,
|
clearChanged,
|
||||||
|
getTitle,
|
||||||
}) {
|
}) {
|
||||||
this.logo = DEFAULT_LOGO;
|
this.logo = DEFAULT_LOGO;
|
||||||
this.owner = null;
|
this.owner = null;
|
||||||
this.map = new Map({ container });
|
this.map = new Map({ container });
|
||||||
|
this.initialData = {};
|
||||||
|
|
||||||
const {
|
const {
|
||||||
lockMapClicks, routerMoveStart, changeMode, pushPolyPoints, map: { map }
|
lockMapClicks, routerMoveStart, changeMode, pushPolyPoints, map: { map }
|
||||||
|
@ -60,7 +62,7 @@ export class Editor {
|
||||||
toggle: this.clearAll,
|
toggle: this.clearAll,
|
||||||
},
|
},
|
||||||
[MODES.CONFIRM_CANCEL]: {
|
[MODES.CONFIRM_CANCEL]: {
|
||||||
toggle: this.stopEditing,
|
toggle: this.cancelEditing,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -79,6 +81,7 @@ export class Editor {
|
||||||
this.setAddress = setAddress;
|
this.setAddress = setAddress;
|
||||||
this.getUser = getUser;
|
this.getUser = getUser;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
|
this.getTitle = getTitle;
|
||||||
|
|
||||||
map.addEventListener('mouseup', this.onClick);
|
map.addEventListener('mouseup', this.onClick);
|
||||||
map.addEventListener('dragstart', () => lockMapClicks(true));
|
map.addEventListener('dragstart', () => lockMapClicks(true));
|
||||||
|
@ -220,18 +223,31 @@ export class Editor {
|
||||||
|
|
||||||
const url = (this.owner && this.owner === id) ? path : random_url;
|
const url = (this.owner && this.owner === id) ? path : random_url;
|
||||||
|
|
||||||
this.setAddress(url);
|
|
||||||
pushPath(`/${url}/edit`);
|
pushPath(`/${url}/edit`);
|
||||||
|
|
||||||
if (this.poly.latlngs && this.poly.latlngs.length > 1) this.poly.poly.enableEdit();
|
if (this.poly.latlngs && this.poly.latlngs.length > 1) this.poly.poly.enableEdit();
|
||||||
|
|
||||||
this.stickers.startEditing();
|
this.stickers.startEditing();
|
||||||
this.setEditing(true);
|
this.setEditing(true);
|
||||||
|
|
||||||
|
const { route, stickers } = this.dumpData();
|
||||||
|
|
||||||
|
this.initialData = {
|
||||||
|
version: 2,
|
||||||
|
title: this.getTitle(),
|
||||||
|
owner: this.owner,
|
||||||
|
address: this.owner === id ? path : null,
|
||||||
|
path: path,
|
||||||
|
route,
|
||||||
|
stickers,
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(this.initialData);
|
||||||
};
|
};
|
||||||
|
|
||||||
stopEditing = () => {
|
stopEditing = () => {
|
||||||
const { path } = getUrlData();
|
const { path } = getUrlData();
|
||||||
pushPath(`/${path}`);
|
pushPath(`/${(this.initialData && this.initialData.path) || path}`);
|
||||||
|
|
||||||
this.changeMode(MODES.NONE);
|
this.changeMode(MODES.NONE);
|
||||||
this.poly.poly.disableEdit();
|
this.poly.poly.disableEdit();
|
||||||
|
@ -239,8 +255,35 @@ export class Editor {
|
||||||
this.setEditing(false);
|
this.setEditing(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
cancelEditing = () => {
|
||||||
|
this.stopEditing();
|
||||||
|
|
||||||
|
console.log('trying to set initial data');
|
||||||
|
|
||||||
|
if (this.hasEmptyHistory()) {
|
||||||
|
this.clearAll();
|
||||||
|
this.startEditing();
|
||||||
|
} else {
|
||||||
|
this.setData(this.initialData);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.clearChanged();
|
||||||
|
};
|
||||||
|
|
||||||
dumpData = () => ({
|
dumpData = () => ({
|
||||||
route: this.poly.dumpData(),
|
route: this.poly.dumpData(),
|
||||||
stickers: this.stickers.dumpData(),
|
stickers: this.stickers.dumpData(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
isEmpty = () => {
|
||||||
|
const { route, stickers } = this.dumpData();
|
||||||
|
|
||||||
|
return (route.length > 1 && stickers.length > 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
hasEmptyHistory = () => {
|
||||||
|
const { route, stickers } = this.initialData;
|
||||||
|
|
||||||
|
return !(route && route.length >= 1 && stickers && stickers.length > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue