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