finally saving things

This commit is contained in:
muerwre 2018-08-30 17:10:33 +07:00
parent e0f5d0238a
commit 47e4f4a97d
22 changed files with 277 additions and 38 deletions

View file

@ -32,3 +32,13 @@ export const getStoredMap = ({ name }) => axios.get(API.GET_MAP, {
action: 'load'
}
}).then(result => (result && result.data && result.data.data && result.data.owner && { ...result.data.data, owner: result.data.owner }));
export const postMap = ({ title, address, route, stickers, id, token }) => axios.post(API.POST_MAP, {
action: 'store',
title,
address,
route,
stickers,
id,
token,
}).then(result => (result && result.data && result.data.data && result.data.owner && { ...result.data.data, owner: result.data.owner }));

12
src/utils/format.js Normal file
View file

@ -0,0 +1,12 @@
const ru = [' ','\\.',',',':','\\?','#','Я','я','Ю','ю','Ч','ч','Ш','ш','Щ','щ','Ж','ж','А','а','Б','б','В','в','Г','г','Д','д','Е','е','Ё','ё','З','з','И','и','Й','й','К','к','Л','л','М','м','Н','н', 'О','о','П','п','Р','р','С','с','Т','т','У','у','Ф','ф','Х','х','Ц','ц','Ы','ы','Ь','ь','Ъ','ъ','Э','э'];
const en = ['_','','','','','','Ya','ya','Yu','yu','Ch','ch','Sh','sh','Sh','sh','Zh','zh','A','a','B','b','V','v','G','g','D','d','E','e','E','e','Z','z','I','i','J','j','K','k','L','l','M','m','N','n', 'O','o','P','p','R','r','S','s','T','t','U','u','F','f','H','h','C','c','Y','y','`','`','\'','\'','E', 'e'];
export const toHours = (info) => {
const hrs = parseInt(Number(info), 10);
const min = Math.round((Number(info) - hrs) * 60);
const lmin = min < 10 ? '0' + min : min;
return `${hrs}:${lmin}`;
};
export const toTranslit = string => ru.reduce((text, el, i) => (text.replace(new RegExp(ru[i], 'g'), en[i])), string);

View file

@ -1,12 +1,13 @@
export const getPath = () => (window.location && window.location.pathname &&
window.location.pathname.replace(/^\//, ''));
export const replacePath = url => window.history.replaceState(url, 'Редактирование маршрута', url);
export const pushPath = url => window.history.pushState(url, 'Редактирование маршрута', url);
export const getUrlData = () => {
const url = getPath();
const [path, mode] = url.split('/');
const { host } = window.location;
return { path, mode };
return { path, mode, host };
};

View file

@ -2,6 +2,15 @@
functions to parse old maps data
*/
export const parseStickerAngle = ({ angle, format }) => parseFloat((format === 'old' ? angle - 3.14 : angle));
export const parseStickerAngle = ({ sticker, version }) => {
console.log('stick', sticker, version);
return sticker && version && parseInt(version, 10) === 2
? parseFloat(sticker.angle)
: parseFloat(sticker.ang - 3.14);
};
export const parseStickerStyle = ({ style, format }) => (format === 'old' ? 'green' : style);
export const parseStickerStyle = ({ sticker, version }) => (
sticker && version && parseInt(version, 10) === 2
? sticker.sticker
: 'basic'
);

View file

@ -1,6 +0,0 @@
export const toHours = (info) => {
const hrs = parseInt(Number(info), 10);
const min = Math.round((Number(info) - hrs) * 60);
const lmin = min < 10 ? '0' + min : min;
return `${hrs}:${lmin}`;
};