mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 19:16:41 +07:00
possibly dealed with setting addresses
This commit is contained in:
parent
13c5ae08d9
commit
ad04704c3e
7 changed files with 65 additions and 17 deletions
|
@ -8,7 +8,7 @@ import { LogoDialog } from '$components/logo/LogoDialog';
|
||||||
import { SaveDialog } from '$components/save/SaveDialog';
|
import { SaveDialog } from '$components/save/SaveDialog';
|
||||||
|
|
||||||
export const EditorDialog = ({
|
export const EditorDialog = ({
|
||||||
mode, routerPoints, editor, activeSticker, logo, user,
|
mode, routerPoints, editor, activeSticker, logo, user, title, address,
|
||||||
}) => {
|
}) => {
|
||||||
const showDialog = (
|
const showDialog = (
|
||||||
mode === MODES.ROUTER
|
mode === MODES.ROUTER
|
||||||
|
@ -25,7 +25,7 @@ export const EditorDialog = ({
|
||||||
{ mode === MODES.STICKERS && <StickersDialog editor={editor} /> }
|
{ mode === MODES.STICKERS && <StickersDialog editor={editor} /> }
|
||||||
{ mode === MODES.TRASH && <TrashDialog editor={editor} /> }
|
{ mode === MODES.TRASH && <TrashDialog editor={editor} /> }
|
||||||
{ mode === MODES.LOGO && <LogoDialog editor={editor} logo={logo} /> }
|
{ mode === MODES.LOGO && <LogoDialog editor={editor} logo={logo} /> }
|
||||||
{ mode === MODES.SAVE && <SaveDialog editor={editor} user={user} /> }
|
{ mode === MODES.SAVE && <SaveDialog editor={editor} user={user} title={title} address={address} /> }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -29,7 +29,7 @@ export class EditorPanel extends React.PureComponent {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {
|
const {
|
||||||
mode, routerPoints, editor, totalDistance, estimateTime, activeSticker, logo, user, editing,
|
mode, routerPoints, editor, totalDistance, estimateTime, activeSticker, logo, user, editing, title, address,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -42,6 +42,8 @@ export class EditorPanel extends React.PureComponent {
|
||||||
editor={editor}
|
editor={editor}
|
||||||
logo={logo}
|
logo={logo}
|
||||||
user={user}
|
user={user}
|
||||||
|
title={title}
|
||||||
|
address={address}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<LogoPreview logo={logo} />
|
<LogoPreview logo={logo} />
|
||||||
|
|
|
@ -8,14 +8,18 @@ import { postMap } from '$utils/api';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
|
|
||||||
export class SaveDialog extends React.Component {
|
export class SaveDialog extends React.Component {
|
||||||
state = {
|
constructor(props) {
|
||||||
address: '',
|
super(props);
|
||||||
title: '',
|
|
||||||
error: '',
|
this.state = {
|
||||||
sending: false,
|
address: props.address || '',
|
||||||
finished: false,
|
title: props.title || '',
|
||||||
overwriting: false,
|
error: '',
|
||||||
};
|
sending: false,
|
||||||
|
finished: false,
|
||||||
|
overwriting: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
getAddress = () => {
|
getAddress = () => {
|
||||||
const { path } = getUrlData();
|
const { path } = getUrlData();
|
||||||
|
|
|
@ -10,6 +10,8 @@ export const DEFAULT_USER = {
|
||||||
role: ROLES.guest,
|
role: ROLES.guest,
|
||||||
routes: [],
|
routes: [],
|
||||||
success: false,
|
success: false,
|
||||||
|
id: null,
|
||||||
|
token: null,
|
||||||
userdata: {
|
userdata: {
|
||||||
name: '',
|
name: '',
|
||||||
agent: '',
|
agent: '',
|
||||||
|
|
|
@ -23,6 +23,8 @@ export class App extends React.Component {
|
||||||
user: {
|
user: {
|
||||||
...DEFAULT_USER,
|
...DEFAULT_USER,
|
||||||
},
|
},
|
||||||
|
title: '',
|
||||||
|
address: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
@ -50,7 +52,6 @@ export class App extends React.Component {
|
||||||
};
|
};
|
||||||
|
|
||||||
startEmptyEditor = () => {
|
startEmptyEditor = () => {
|
||||||
console.log('starting empty');
|
|
||||||
const { user } = this.state;
|
const { user } = this.state;
|
||||||
if (!user || !user.random_url || !user.id) return;
|
if (!user || !user.random_url || !user.id) return;
|
||||||
|
|
||||||
|
@ -62,6 +63,9 @@ export class App extends React.Component {
|
||||||
this.hideLoader();
|
this.hideLoader();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
setTitle = title => this.setState({ title });
|
||||||
|
setAddress = address => this.setState({ address });
|
||||||
|
|
||||||
setDataOnLoad = data => {
|
setDataOnLoad = data => {
|
||||||
this.editor.setData(data);
|
this.editor.setData(data);
|
||||||
this.hideLoader();
|
this.hideLoader();
|
||||||
|
@ -99,6 +103,8 @@ export class App extends React.Component {
|
||||||
this.setState({ editing });
|
this.setState({ editing });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getUser = () => this.state.user;
|
||||||
|
|
||||||
editor = new Editor({
|
editor = new Editor({
|
||||||
container: 'map',
|
container: 'map',
|
||||||
mode: this.state.mode,
|
mode: this.state.mode,
|
||||||
|
@ -108,6 +114,9 @@ export class App extends React.Component {
|
||||||
setActiveSticker: this.setActiveSticker,
|
setActiveSticker: this.setActiveSticker,
|
||||||
setLogo: this.setLogo,
|
setLogo: this.setLogo,
|
||||||
setEditing: this.setEditing,
|
setEditing: this.setEditing,
|
||||||
|
setTitle: this.setTitle,
|
||||||
|
setAddress: this.setAddress,
|
||||||
|
getUser: this.getUser,
|
||||||
});
|
});
|
||||||
|
|
||||||
authInit = () => {
|
authInit = () => {
|
||||||
|
@ -132,6 +141,10 @@ export class App extends React.Component {
|
||||||
setUser = user => {
|
setUser = user => {
|
||||||
if (!user.token || !user.id) return;
|
if (!user.token || !user.id) return;
|
||||||
|
|
||||||
|
if (this.state.user.id === this.editor.owner) {
|
||||||
|
this.editor.owner = user.id;
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
user: {
|
user: {
|
||||||
...DEFAULT_USER,
|
...DEFAULT_USER,
|
||||||
|
@ -149,6 +162,10 @@ export class App extends React.Component {
|
||||||
getUserData = () => getData('user') || null;
|
getUserData = () => getData('user') || null;
|
||||||
|
|
||||||
userLogout = () => {
|
userLogout = () => {
|
||||||
|
if (this.state.user.id === this.editor.owner) {
|
||||||
|
this.editor.owner = null;
|
||||||
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
user: {
|
user: {
|
||||||
...DEFAULT_USER,
|
...DEFAULT_USER,
|
||||||
|
@ -162,7 +179,7 @@ export class App extends React.Component {
|
||||||
const {
|
const {
|
||||||
editor,
|
editor,
|
||||||
state: {
|
state: {
|
||||||
mode, routerPoints, totalDistance, estimateTime, activeSticker, logo, user, editing,
|
mode, routerPoints, totalDistance, estimateTime, activeSticker, logo, user, editing, title, address
|
||||||
},
|
},
|
||||||
} = this;
|
} = this;
|
||||||
|
|
||||||
|
@ -190,6 +207,8 @@ export class App extends React.Component {
|
||||||
logo={logo}
|
logo={logo}
|
||||||
user={user}
|
user={user}
|
||||||
editing={editing}
|
editing={editing}
|
||||||
|
title={title}
|
||||||
|
address={address}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -19,6 +19,9 @@ export class Editor {
|
||||||
setActiveSticker,
|
setActiveSticker,
|
||||||
setLogo,
|
setLogo,
|
||||||
setEditing,
|
setEditing,
|
||||||
|
setTitle,
|
||||||
|
setAddress,
|
||||||
|
getUser,
|
||||||
}) {
|
}) {
|
||||||
this.logo = DEFAULT_LOGO;
|
this.logo = DEFAULT_LOGO;
|
||||||
this.owner = null;
|
this.owner = null;
|
||||||
|
@ -66,6 +69,9 @@ export class Editor {
|
||||||
this.setLogo = setLogo;
|
this.setLogo = setLogo;
|
||||||
this.setMode = setMode;
|
this.setMode = setMode;
|
||||||
this.setEditing = setEditing;
|
this.setEditing = setEditing;
|
||||||
|
this.setTitle = setTitle;
|
||||||
|
this.setAddress = setAddress;
|
||||||
|
this.getUser = getUser;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
|
|
||||||
map.addEventListener('mouseup', this.onClick);
|
map.addEventListener('mouseup', this.onClick);
|
||||||
|
@ -171,8 +177,12 @@ export class Editor {
|
||||||
this.changeMode(MODES.NONE);
|
this.changeMode(MODES.NONE);
|
||||||
};
|
};
|
||||||
|
|
||||||
setData = ({ route, stickers, version = 1, owner }) => {
|
setData = ({ route, stickers, version = 1, owner, title, address }) => {
|
||||||
console.log('setting?', stickers);
|
this.setTitle(title || '');
|
||||||
|
this.setAddress(address || '');
|
||||||
|
|
||||||
|
console.log('setting address', address);
|
||||||
|
|
||||||
if (route) {
|
if (route) {
|
||||||
this.poly.setPoints(route);
|
this.poly.setPoints(route);
|
||||||
}
|
}
|
||||||
|
@ -198,7 +208,14 @@ export class Editor {
|
||||||
|
|
||||||
startEditing = () => {
|
startEditing = () => {
|
||||||
const { path } = getUrlData();
|
const { path } = getUrlData();
|
||||||
pushPath(`/${path}/edit`);
|
const { random_url, id } = this.getUser();
|
||||||
|
|
||||||
|
// console.log('ID', id, this.owner);
|
||||||
|
|
||||||
|
const url = (this.owner && this.owner === id) ? path : random_url;
|
||||||
|
|
||||||
|
this.setAddress(url);
|
||||||
|
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();
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,11 @@ export const getStoredMap = ({ name }) => axios.get(API.GET_MAP, {
|
||||||
name,
|
name,
|
||||||
action: 'load'
|
action: 'load'
|
||||||
}
|
}
|
||||||
}).then(result => (result && result.data && result.data.data && { ...result.data.data, owner: (result.data.owner || null) }));
|
}).then(result => (result && result.data && result.data.data && {
|
||||||
|
...result.data.data,
|
||||||
|
owner: (result.data.owner || null),
|
||||||
|
address: (result.data.name || name),
|
||||||
|
}));
|
||||||
|
|
||||||
export const postMap = ({
|
export const postMap = ({
|
||||||
title, address, route, stickers, id, token, force,
|
title, address, route, stickers, id, token, force,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue