mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 11:06:40 +07:00
backend: route save / restore
This commit is contained in:
parent
032821329b
commit
d932fcb287
17 changed files with 163 additions and 43 deletions
|
@ -59,14 +59,14 @@ export class SaveDialog extends React.Component<Props, State> {
|
|||
|
||||
render() {
|
||||
const { title } = this.state;
|
||||
const { save_error, save_finished, save_overwriting, save_processing } = this.props;
|
||||
const { save_error, save_finished, save_overwriting } = this.props;
|
||||
const { host } = getUrlData();
|
||||
|
||||
return (
|
||||
<div className="helper save-helper">
|
||||
<div className="save-title">
|
||||
<div className="save-title-input">
|
||||
<label className="save-title-label">Название</label>
|
||||
<div className="save-title-label">Название</div>
|
||||
<input type="text" value={title} onChange={this.setTitle} autoFocus readOnly={save_finished} />
|
||||
</div>
|
||||
</div>
|
||||
|
@ -86,21 +86,21 @@ export class SaveDialog extends React.Component<Props, State> {
|
|||
<div>
|
||||
|
||||
{ !save_finished &&
|
||||
<div className="button" onClick={this.cancelSaving}>Отмена</div>
|
||||
<div className="button" onClick={this.cancelSaving}>Отмена</div>
|
||||
}
|
||||
|
||||
{
|
||||
!save_finished && !save_overwriting &&
|
||||
<div className="button primary" onClick={this.sendSaveRequest}>Сохранить</div>
|
||||
<div className="button primary" onClick={this.sendSaveRequest}>Сохранить</div>
|
||||
}
|
||||
|
||||
{
|
||||
save_overwriting &&
|
||||
<div className="button danger" onClick={this.forceSaveRequest}>Перезаписать</div>
|
||||
<div className="button danger" onClick={this.forceSaveRequest}>Перезаписать</div>
|
||||
}
|
||||
|
||||
{ save_finished &&
|
||||
<div className="button success" onClick={this.cancelSaving}>Отлично, спасибо!</div>
|
||||
<div className="button success" onClick={this.cancelSaving}>Отлично, спасибо!</div>
|
||||
}
|
||||
|
||||
</div>
|
||||
|
|
|
@ -5,6 +5,6 @@ export const API = {
|
|||
COMPOSE: `${SERVER}/engine/composerOrchid.php`,
|
||||
GET_GUEST: `${TEST}/auth`,
|
||||
CHECK_TOKEN: `${TEST}/auth`,
|
||||
GET_MAP: `${SERVER}/engine/authOrchid.php`,
|
||||
POST_MAP: `${SERVER}/engine/authOrchid.php?action=store`,
|
||||
GET_MAP: `${TEST}/route`,
|
||||
POST_MAP: `${TEST}/route`,
|
||||
};
|
||||
|
|
|
@ -229,7 +229,9 @@ export class Editor {
|
|||
this.setTitle(title || '');
|
||||
const { id } = this.getUser();
|
||||
|
||||
if (address && id && owner && id === owner) this.setAddress(address);
|
||||
if (address && id && owner && id === owner.id) {
|
||||
this.setAddress(address);
|
||||
}
|
||||
|
||||
if (route) this.poly.setPoints(route);
|
||||
|
||||
|
@ -274,7 +276,7 @@ export class Editor {
|
|||
|
||||
this.setInitialData();
|
||||
|
||||
const url = (this.owner && this.owner === id) ? path : random_url;
|
||||
const url = (this.owner && this.owner.id === id) ? path : random_url;
|
||||
|
||||
pushPath(`/${url}/edit`);
|
||||
|
||||
|
|
|
@ -199,11 +199,12 @@ function* sendSaveRequestSaga({ title, address, force }) {
|
|||
if (editor.isEmpty) return yield put(setSaveError(TIPS.SAVE_EMPTY));
|
||||
|
||||
const { route, stickers } = editor.dumpData();
|
||||
const { logo, distance } = yield select(getState);
|
||||
const { id, token } = yield select(getUser);
|
||||
|
||||
const { result, timeout, cancel } = yield race({
|
||||
result: postMap({
|
||||
id, token, route, stickers, title, force, address
|
||||
id, token, route, stickers, title, force, address, logo, distance,
|
||||
}),
|
||||
timeout: delay(10000),
|
||||
cancel: take(ACTIONS.RESET_SAVE_DIALOG),
|
||||
|
|
|
@ -5,18 +5,10 @@ import { API } from '$constants/api';
|
|||
const report = console.warn;
|
||||
|
||||
export const checkUserToken = ({ id, token }) => axios.get(API.CHECK_TOKEN, {
|
||||
params: {
|
||||
id,
|
||||
token,
|
||||
action: 'check_token',
|
||||
}
|
||||
params: { id, token }
|
||||
}).then(result => (result && result.data && { ...result.data, id, token }));
|
||||
|
||||
export const getGuestToken = () => axios.get(API.GET_GUEST, {
|
||||
params: {
|
||||
action: 'gen_guest_token'
|
||||
}
|
||||
}).then(result => (result && result.data));
|
||||
export const getGuestToken = () => axios.get(API.GET_GUEST).then(result => (result && result.data));
|
||||
|
||||
export const getMergedImage = ({ placement, callback }) => (
|
||||
axios.get(API.COMPOSE, {
|
||||
|
@ -27,20 +19,12 @@ export const getMergedImage = ({ placement, callback }) => (
|
|||
);
|
||||
|
||||
export const getStoredMap = ({ name }) => axios.get(API.GET_MAP, {
|
||||
params: {
|
||||
name,
|
||||
action: 'load'
|
||||
}
|
||||
}).then(result => (result && result.data && result.data.data && {
|
||||
...result.data.data,
|
||||
owner: (result.data.owner || null),
|
||||
address: (result.data.name || name),
|
||||
}));
|
||||
params: { name }
|
||||
}).then(result => (result && result.data));
|
||||
|
||||
export const postMap = ({
|
||||
title, address, route, stickers, id, token, force,
|
||||
title, address, route, stickers, id, token, force, logo, distance,
|
||||
}) => axios.post(API.POST_MAP, {
|
||||
action: 'store',
|
||||
title,
|
||||
address,
|
||||
route,
|
||||
|
@ -48,4 +32,6 @@ export const postMap = ({
|
|||
id,
|
||||
token,
|
||||
force,
|
||||
logo,
|
||||
distance,
|
||||
}).then(result => (result && result.data && result.data));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue