From 2144af9899e8124fabc20daf913dc122e366de1e Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Thu, 12 Dec 2019 17:22:57 +0700 Subject: [PATCH] modified to match golang backend --- src/components/dialogs/MapListDialog.tsx | 18 +-- src/components/maps/RouteRowDrop.tsx | 6 +- src/components/maps/RouteRowEditor.tsx | 6 +- src/components/maps/RouteRowView.tsx | 133 ++++++++++++----------- src/components/maps/RouteRowWrapper.tsx | 133 ++++++++++++----------- src/components/panels/UserPanel.tsx | 4 +- src/constants/api.ts | 8 +- src/constants/dialogs.ts | 20 ++-- src/modules/Editor.ts | 12 +- src/redux/user/actions.ts | 4 +- src/redux/user/reducer.ts | 20 ++-- src/redux/user/sagas.ts | 93 ++++++++++------ src/utils/api.ts | 74 +++++++------ 13 files changed, 296 insertions(+), 235 deletions(-) diff --git a/src/components/dialogs/MapListDialog.tsx b/src/components/dialogs/MapListDialog.tsx index 5a30c87..8e52106 100644 --- a/src/components/dialogs/MapListDialog.tsx +++ b/src/components/dialogs/MapListDialog.tsx @@ -16,7 +16,7 @@ import { isMobile } from '$utils/window'; import classnames from 'classnames'; import * as Range from 'rc-slider/lib/Range'; -import { TABS } from '$constants/dialogs'; +import { TABS, TABS_TITLES } from '$constants/dialogs'; import { Icon } from '$components/panels/Icon'; import { pushPath } from '$utils/history'; import { IRootState, IRouteListItem } from '$redux/user/reducer'; @@ -110,12 +110,12 @@ class Component extends React.Component { - this.props.dropRoute(_id); + dropRoute = (address: string): void => { + this.props.dropRoute(address); }; - modifyRoute = ({ _id, title, is_public }: { _id: string, title: string, is_public: boolean }): void => { - this.props.modifyRoute(_id, { title, is_public }); + modifyRoute = ({ address, title, is_public }: { address: string, title: string, is_public: boolean }): void => { + this.props.modifyRoute(address, { title, is_public }); this.stopEditing(); }; @@ -161,13 +161,13 @@ class Component extends React.Component { - Object.keys(TABS).map(item => (role === ROLES.admin || item !== 'all') && ( + Object.values(TABS).map(item => (role === ROLES.admin || item !== TABS.PENDING) && (
this.props.searchSetTab(item)} key={item} > - {TABS[item]} + {TABS_TITLES[item]}
)) } @@ -211,9 +211,9 @@ class Component extends React.Component => (
-
Удалить
+
Удалить
Отмена
diff --git a/src/components/maps/RouteRowEditor.tsx b/src/components/maps/RouteRowEditor.tsx index eb08ff5..d8471db 100644 --- a/src/components/maps/RouteRowEditor.tsx +++ b/src/components/maps/RouteRowEditor.tsx @@ -6,7 +6,7 @@ import { MapListDialog } from "$components/dialogs/MapListDialog"; interface Props { title: string; - _id: string; + address: string; is_public: boolean, modifyRoute: typeof MapListDialog.modifyRoute, } @@ -29,10 +29,10 @@ export class RouteRowEditor extends React.Component { stopEditing = () => { const { state: { title, is_public }, - props: { _id } + props: { address } } = this; - this.props.modifyRoute({ _id, title, is_public }) + this.props.modifyRoute({ address, title, is_public }) }; setPublic = () => this.setState({ is_public: !this.state.is_public }); diff --git a/src/components/maps/RouteRowView.tsx b/src/components/maps/RouteRowView.tsx index 42027dd..85c0811 100644 --- a/src/components/maps/RouteRowView.tsx +++ b/src/components/maps/RouteRowView.tsx @@ -1,93 +1,100 @@ // @flow -import * as React from 'react'; -import { Icon } from '$components/panels/Icon'; +import * as React from "react"; +import { Icon } from "$components/panels/Icon"; import { MapListDialog } from "$components/dialogs/MapListDialog"; import { Tooltip } from "$components/panels/Tooltip"; import { ReactElement } from "react"; -import classnames from 'classnames'; +import classnames from "classnames"; import { toggleRouteStarred } from "$redux/user/actions"; +import { TABS } from "$constants/dialogs"; interface Props { - tab: string, + tab: string; - _id: string, - title: string, - distance: number, - is_public: boolean, - is_admin: boolean, - is_starred: boolean, + address: string; + title: string; + distance: number; + is_public: boolean; + is_admin: boolean; + is_published: boolean; - openRoute: typeof MapListDialog.openRoute, - toggleStarred: typeof MapListDialog.toggleStarred, - startEditing: typeof MapListDialog.startEditing, - stopEditing: typeof MapListDialog.stopEditing, - showMenu: typeof MapListDialog.showMenu, - hideMenu: typeof MapListDialog.hideMenu, - showDropCard: typeof MapListDialog.showDropCard, + openRoute: typeof MapListDialog.openRoute; + toggleStarred: typeof MapListDialog.toggleStarred; + startEditing: typeof MapListDialog.startEditing; + stopEditing: typeof MapListDialog.stopEditing; + showMenu: typeof MapListDialog.showMenu; + hideMenu: typeof MapListDialog.hideMenu; + showDropCard: typeof MapListDialog.showDropCard; } export const RouteRowView = ({ - title, distance, _id, openRoute, tab, startEditing, showMenu, showDropCard, hideMenu, is_admin, is_starred, toggleStarred, + title, + distance, + address, + openRoute, + tab, + startEditing, + showMenu, + showDropCard, + hideMenu, + is_admin, + is_published, + toggleStarred }: Props): ReactElement => ( -
- { - (tab === 'all' || tab === 'starred') && is_admin && -
- { - is_starred - ? - : - } +
+ {(tab === TABS.PENDING || tab === TABS.STARRED) && is_admin && ( +
+ {is_published ? ( + + ) : ( + + )}
- } -
openRoute(_id)} - > + )} +
openRoute(address)}>
- { - (tab === 'my' || !is_admin) && is_starred && -
- } - - {(title || _id)} - + {(tab === "my" || !is_admin) && is_published && ( +
+ +
+ )} + {title || address}
- {_id} + {address} - {(distance && `${distance} km`) || '0 km'} + {(distance && `${distance} km`) || "0 km"}
- { - tab === 'my' && - -
- -
-
- Удалить - -
-
- Редактировать - -
+ {tab === "my" && ( + +
+ +
+
+ Удалить + +
+
+ Редактировать +
- - } +
+
+ )}
); diff --git a/src/components/maps/RouteRowWrapper.tsx b/src/components/maps/RouteRowWrapper.tsx index a8379d4..a681974 100644 --- a/src/components/maps/RouteRowWrapper.tsx +++ b/src/components/maps/RouteRowWrapper.tsx @@ -1,5 +1,5 @@ -import * as React from 'react'; -import classnames from 'classnames'; +import * as React from "react"; +import classnames from "classnames"; import { MapListDialog } from "$components/dialogs/MapListDialog"; import { RouteRowView } from "$components/maps/RouteRowView"; import { RouteRowEditor } from "$components/maps/RouteRowEditor"; @@ -7,76 +7,85 @@ import { RouteRowDrop } from "$components/maps/RouteRowDrop"; import { ReactElement } from "react"; interface Props { - _id: string, - tab: string, - title: string, - distance: number, - is_public: boolean, - is_starred: boolean, + address: string; + tab: string; + title: string; + distance: number; + is_public: boolean; + is_published: boolean; - is_admin: boolean, - is_editing_target: boolean, - is_menu_target: boolean, + is_admin: boolean; + is_editing_target: boolean; + is_menu_target: boolean; - openRoute: typeof MapListDialog.openRoute, - startEditing: typeof MapListDialog.startEditing, - stopEditing: typeof MapListDialog.stopEditing, - showMenu: typeof MapListDialog.showMenu, - hideMenu: typeof MapListDialog.hideMenu, - showDropCard: typeof MapListDialog.showDropCard, - dropRoute: typeof MapListDialog.dropRoute, - modifyRoute: typeof MapListDialog.modifyRoute, - toggleStarred: typeof MapListDialog.toggleStarred, + openRoute: typeof MapListDialog.openRoute; + startEditing: typeof MapListDialog.startEditing; + stopEditing: typeof MapListDialog.stopEditing; + showMenu: typeof MapListDialog.showMenu; + hideMenu: typeof MapListDialog.hideMenu; + showDropCard: typeof MapListDialog.showDropCard; + dropRoute: typeof MapListDialog.dropRoute; + modifyRoute: typeof MapListDialog.modifyRoute; + toggleStarred: typeof MapListDialog.toggleStarred; - is_editing_mode: 'edit' | 'drop', + is_editing_mode: "edit" | "drop"; } export const RouteRowWrapper = ({ - title, distance, _id, openRoute, tab, startEditing, showMenu, - showDropCard, is_public, is_editing_target, is_menu_target, is_editing_mode, - dropRoute, stopEditing, modifyRoute, hideMenu, is_admin, is_starred, toggleStarred, + title, + distance, + address, + openRoute, + tab, + startEditing, + showMenu, + showDropCard, + is_public, + is_editing_target, + is_menu_target, + is_editing_mode, + dropRoute, + stopEditing, + modifyRoute, + hideMenu, + is_admin, + is_published, + toggleStarred }: Props): ReactElement => (
- { - is_editing_target && is_editing_mode === 'edit' && - - } - { - is_editing_target && is_editing_mode === 'drop' && - - } - { - !is_editing_target && - - } + {is_editing_target && is_editing_mode === "edit" && ( + + )} + {is_editing_target && is_editing_mode === "drop" && ( + + )} + {!is_editing_target && ( + + )}
); diff --git a/src/components/panels/UserPanel.tsx b/src/components/panels/UserPanel.tsx index 783ac71..aea5d13 100644 --- a/src/components/panels/UserPanel.tsx +++ b/src/components/panels/UserPanel.tsx @@ -11,7 +11,7 @@ import { Icon } from '$components/panels/Icon'; import classnames from 'classnames'; import { CLIENT } from '$config/frontend'; -import { DIALOGS } from '$constants/dialogs'; +import { DIALOGS, TABS } from '$constants/dialogs'; import { IRootState } from "$redux/user/reducer"; import { Tooltip } from "$components/panels/Tooltip"; import { TitleDialog } from "$components/dialogs/TitleDialog"; @@ -65,7 +65,7 @@ export class Component extends React.PureComponent { setMenuOpened = () => this.setState({ menuOpened: !this.state.menuOpened }); openMapsDialog = () => { - this.props.openMapDialog('my'); + this.props.openMapDialog(TABS.MY); }; openAppInfoDialog = () => { diff --git a/src/constants/api.ts b/src/constants/api.ts index fa343c7..6e0a243 100644 --- a/src/constants/api.ts +++ b/src/constants/api.ts @@ -1,16 +1,16 @@ import { CLIENT } from '$config/frontend'; -export const API: { [x: string]: string } = { +export const API = { GET_GUEST: `${CLIENT.API_ADDR}/api/auth/`, CHECK_TOKEN: `${CLIENT.API_ADDR}/api/auth/`, - IFRAME_LOGIN_VK: `${CLIENT.API_ADDR}/api/auth/vk/`, + IFRAME_LOGIN_VK: `${CLIENT.API_ADDR}/api/auth/vk`, GET_MAP: `${CLIENT.API_ADDR}/api/route/`, POST_MAP: `${CLIENT.API_ADDR}/api/route/`, - GET_ROUTE_LIST: `${CLIENT.API_ADDR}/api/route/list/`, + GET_ROUTE_LIST: tab => `${CLIENT.API_ADDR}/api/route/list/${tab}`, DROP_ROUTE: `${CLIENT.API_ADDR}/api/route/`, MODIFY_ROUTE: `${CLIENT.API_ADDR}/api/route/`, - SET_STARRED: `${CLIENT.API_ADDR}/api/route/publish/`, + SET_STARRED: `${CLIENT.API_ADDR}/api/route/publish`, }; export const API_RETRY_INTERVAL = 10; diff --git a/src/constants/dialogs.ts b/src/constants/dialogs.ts index 93cec51..1291b6c 100644 --- a/src/constants/dialogs.ts +++ b/src/constants/dialogs.ts @@ -5,9 +5,9 @@ export interface IDialogs { } export interface IMapTabs { - my: string, - all: string, - starred: string, + MY: string, + PENDING: string, + STARRED: string, } export const DIALOGS: IDialogs = ({ @@ -16,8 +16,14 @@ export const DIALOGS: IDialogs = ({ APP_INFO: 'APP_INFO', }); -export const TABS: IMapTabs = ({ - my: 'Мои', - all: 'Заявки', - starred: 'Каталог', +export const TABS: IMapTabs = { + MY: 'my', + PENDING: 'pending', + STARRED: 'starred', +} + +export const TABS_TITLES = ({ + [TABS.MY]: 'Мои', + [TABS.PENDING]: 'Заявки', + [TABS.STARRED]: 'Каталог', }); diff --git a/src/modules/Editor.ts b/src/modules/Editor.ts index 7f97c62..b3c0e6a 100644 --- a/src/modules/Editor.ts +++ b/src/modules/Editor.ts @@ -45,7 +45,7 @@ interface IEditor { stickers: any, provider: IRootState['provider'], is_public: IRootState['is_public'], - is_starred: IRootState['is_starred'], + is_published: IRootState['is_published'], description: IRootState['description'], logo: IRootState['logo'], }; @@ -160,7 +160,7 @@ export class Editor { stickers: null, provider: null, is_public: false, - is_starred: false, + is_published: false, description: '', logo: null, }; @@ -320,7 +320,7 @@ export class Editor { provider = DEFAULT_PROVIDER, logo = DEFAULT_LOGO, is_public, - is_starred, + is_published, description, }: Partial): void => { this.setTitle(title || ''); @@ -348,7 +348,7 @@ export class Editor { } this.setPublic(is_public); - this.setStarred(is_starred); + this.setStarred(is_published); this.setDescription(description); this.setLogo((logo && LOGOS[DEFAULT_LOGO] && logo) || DEFAULT_LOGO); @@ -382,7 +382,7 @@ export class Editor { setInitialData = (): void => { const { path } = getUrlData(); const { id } = this.getUser(); - const { is_public, logo, is_starred , description} = this.getState(); + const { is_public, logo, is_published , description} = this.getState(); const { route, stickers, provider } = this.dumpData(); this.initialData = { @@ -396,7 +396,7 @@ export class Editor { provider, is_public, logo, - is_starred, + is_published, description, }; }; diff --git a/src/redux/user/actions.ts b/src/redux/user/actions.ts index b98c392..5f43ab1 100644 --- a/src/redux/user/actions.ts +++ b/src/redux/user/actions.ts @@ -17,7 +17,7 @@ export const setDescription = description => ({ type: ACTIONS.SET_DESCRIPTION, d export const setAddress = address => ({ type: ACTIONS.SET_ADDRESS, address }); export const setAddressOrigin = address_origin => ({ type: ACTIONS.SET_ADDRESS_ORIGIN, address_origin }); export const setPublic = is_public => ({ type: ACTIONS.SET_PUBLIC, is_public }); -export const setStarred = is_starred => ({ type: ACTIONS.SET_STARRED, is_starred }); +export const setStarred = is_published => ({ type: ACTIONS.SET_STARRED, is_published }); export const setSpeed = speed => ({ type: ACTIONS.SET_SPEED, speed }); export const startEditing = () => ({ type: ACTIONS.START_EDITING }); @@ -99,4 +99,4 @@ export const modifyRoute = (address: string, { title, is_public }: { title: stri type: ACTIONS.MODIFY_ROUTE, address, title, is_public }); export const toggleRouteStarred = (address: string) => ({ type: ACTIONS.TOGGLE_ROUTE_STARRED, address }); -export const setRouteStarred = (address: string, is_starred: boolean) => ({ type: ACTIONS.SET_ROUTE_STARRED, address, is_starred }); +export const setRouteStarred = (address: string, is_published: boolean) => ({ type: ACTIONS.SET_ROUTE_STARRED, address, is_published }); diff --git a/src/redux/user/reducer.ts b/src/redux/user/reducer.ts index 335ce6a..ca57a7f 100644 --- a/src/redux/user/reducer.ts +++ b/src/redux/user/reducer.ts @@ -20,7 +20,7 @@ export interface IRoute { stickers: IStickerDump[], provider: IRootState['provider'], is_public: IRootState['is_public'], - is_published: IRootState['is_starred'], + is_published: IRootState['is_published'], description: IRootState['description'], logo: IRootState['logo'], distance: IRootState['distance'] @@ -31,7 +31,7 @@ export interface IRouteListItem { title: string, distance: number, is_public: boolean, - is_starred: boolean, + is_published: boolean, updated_at: string, } @@ -54,7 +54,7 @@ export interface IRootReducer { provider: keyof typeof PROVIDERS, markers_shown: boolean, - is_starred: boolean, + is_published: boolean, is_public: boolean, is_empty: boolean, is_routing: boolean, @@ -271,7 +271,7 @@ const searchSetTab: ActionHandler = (state, ...state.routes, filter: { ...state.routes.filter, - tab: Object.keys(TABS).indexOf(tab) >= 0 ? tab : TABS[Object.keys(TABS)[0]], + tab: Object.values(TABS).indexOf(tab) >= 0 ? tab : TABS[Object.values(TABS)[0]], } } }); @@ -304,7 +304,7 @@ const searchSetLoading: ActionHandler = }); const setPublic: ActionHandler = (state, { is_public = false }) => ({ ...state, is_public }); -const setStarred: ActionHandler = (state, { is_starred = false }) => ({ ...state, is_starred }); +const setStarred: ActionHandler = (state, { is_published = false }) => ({ ...state, is_published }); const setSpeed: ActionHandler = (state, { speed = 15 }) => ({ ...state, @@ -335,16 +335,16 @@ const setIsRouting: ActionHandler = (state, is_routing, }); -const setRouteStarred: ActionHandler = (state, { address, is_starred }) => ({ +const setRouteStarred: ActionHandler = (state, { address, is_published }) => ({ ...state, routes: { ...state.routes, list: ( state.routes.list - .map(el => el.address === address ? { ...el, is_starred } : el) + .map(el => el.address === address ? { ...el, is_published } : el) .filter(el => ( - (state.routes.filter.tab === 'starred' && el.is_starred) || - (state.routes.filter.tab === 'all' && !el.is_starred) + (state.routes.filter.tab === TABS.STARRED && el.is_published) || + (state.routes.filter.tab === TABS.PENDING && !el.is_published) )) ) } @@ -421,7 +421,7 @@ export const INITIAL_STATE: IRootReducer = { changed: false, editing: false, - is_starred: false, + is_published: false, is_public: false, is_empty: true, is_routing: false, diff --git a/src/redux/user/sagas.ts b/src/redux/user/sagas.ts index d48b9ae..ee79778 100644 --- a/src/redux/user/sagas.ts +++ b/src/redux/user/sagas.ts @@ -82,7 +82,7 @@ import { } from "$utils/renderer"; import { LOGOS } from "$constants/logos"; import { DEFAULT_PROVIDER } from "$constants/providers"; -import { DIALOGS } from "$constants/dialogs"; +import { DIALOGS, TABS } from "$constants/dialogs"; import * as ActionCreators from "$redux/user/actions"; import { IRootState } from "$redux/user/reducer"; @@ -152,7 +152,9 @@ function* stopEditingSaga() { } function* loadMapSaga(path) { - const { data: { route, error, random_url } }: Unwrap = yield call(getStoredMap, { name: path }); + const { + data: { route, error, random_url } + }: Unwrap = yield call(getStoredMap, { name: path }); if (route && !error) { yield editor.clearAll(); @@ -161,11 +163,11 @@ function* loadMapSaga(path) { yield editor.setInitialData(); yield put(setChanged(false)); - + return { route, random_url }; } - return null + return null; } function* replaceAddressIfItsBusy(destination, original) { @@ -189,7 +191,7 @@ function* setReadySaga() { hideLoader(); yield call(checkOSRMServiceSaga); - yield put(searchSetTab("my")); + yield put(searchSetTab(TABS.MY)); } function* mapInitSaga() { @@ -218,7 +220,13 @@ function* mapInitSaga() { if (map && map.route) { if (mode && mode === "edit") { - if (map && map.route && map.route.owner && mode === "edit" && map.route.owner !== id) { + if ( + map && + map.route && + map.route.owner && + mode === "edit" && + map.route.owner !== id + ) { yield call(setReadySaga); yield call(replaceAddressIfItsBusy, map.random_url, map.address); } else { @@ -403,19 +411,20 @@ function* sendSaveRequestSaga({ yield put(setSaveLoading(false)); if (cancel) return yield put(setMode(MODES.NONE)); - if (result && result.mode === "overwriting") + + if (result && result.data.code === "already_exist") return yield put(setSaveOverwrite()); - if (result && result.mode === "exists") + if (result && result.data.code === "conflict") return yield put(setSaveError(TIPS.SAVE_EXISTS)); - if (timeout || !result || !result.success || !result.address) + if (timeout || !result || !result.data.route || !result.data.route.address) return yield put(setSaveError(TIPS.SAVE_TIMED_OUT)); return yield put( setSaveSuccess({ - address: result.address, - title: result.title, - is_public: result.is_public, - description: result.description, + address: result.data.route.address, + title: result.data.route.title, + is_public: result.data.route.is_public, + description: result.data.route.description, save_error: TIPS.SAVE_SUCCESS }) @@ -533,8 +542,7 @@ function* locationChangeSaga({ const { address, ready, - user: { id, random_url }, - is_public + user: { id, random_url } } = yield select(getState); if (!ready) return; @@ -544,7 +552,14 @@ function* locationChangeSaga({ if (address !== path) { const map = yield call(loadMapSaga, path); - if (map && map.route && map.route.owner && mode === "edit" && map.route.owner !== id) { + if ( + map && + map.route && + map.route.owner && + mode === "edit" && + map.route.owner !== id + ) { + console.log("replace address if its busy"); return yield call(replaceAddressIfItsBusy, map.random_url, map.address); } } else if (mode === "edit" && editor.owner !== id) { @@ -608,7 +623,7 @@ function* keyPressedSaga({ } function* searchGetRoutes() { - const { id, token } = yield select(getUser); + const { token } = yield select(getUser); const { routes: { @@ -669,7 +684,7 @@ function* searchSetSagaWorker() { function* searchSetSaga() { yield put(searchSetLoading(true)); yield put(mapsSetShift(0)); - yield delay(500); + yield delay(300); yield call(searchSetSagaWorker); } @@ -772,30 +787,45 @@ function* mapsLoadMoreSaga() { if (loading || list.length >= limit || limit === 0) return; - yield delay(100); + yield delay(50); yield put(searchSetLoading(true)); yield put(mapsSetShift(shift + step)); - const result = yield call(searchGetRoutes); + const { + data: { + limits: { min, max, count }, + filter: { shift: resp_shift, step: resp_step }, + routes + } + }: Unwrap = yield call(searchGetRoutes); if ( - (filter.min > result.min && filter.distance[0] <= filter.min) || - (filter.max < result.max && filter.distance[1] >= filter.max) + (filter.min > min && filter.distance[0] <= filter.min) || + (filter.max < max && filter.distance[1] >= filter.max) ) { yield put( searchChangeDistance([ - filter.min > result.min && filter.distance[0] <= filter.min - ? result.min + filter.min > min && filter.distance[0] <= filter.min + ? min : filter.distance[0], - filter.max < result.max && filter.distance[1] >= filter.max - ? result.max + filter.max < max && filter.distance[1] >= filter.max + ? max : filter.distance[1] ]) ); } - yield put(searchPutRoutes({ ...result, list: [...list, ...result.list] })); + yield put( + searchPutRoutes({ + min, + max, + limit: count, + shift: resp_shift, + step: resp_step, + list: [...list, ...routes] + }) + ); yield put(searchSetLoading(false)); } @@ -875,17 +905,16 @@ function* toggleRouteStarredSaga({ }: IState["user"] = yield select(getState); const route = list.find(el => el.address === address); - const { id, token } = yield select(getUser); + const { token } = yield select(getUser); - yield put(setRouteStarred(address, !route.is_starred)); + yield put(setRouteStarred(address, !route.is_published)); const result = yield sendRouteStarred({ - id, token, address, - is_starred: !route.is_starred + is_published: !route.is_published }); - if (!result) return yield put(setRouteStarred(address, route.is_starred)); + if (!result) return yield put(setRouteStarred(address, route.is_published)); } export function* userSaga() { diff --git a/src/utils/api.ts b/src/utils/api.ts index 269cd29..4423b8b 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -90,25 +90,35 @@ export const postMap = ({ is_public, description, token -}: Partial & { force: boolean; token: string }) => +}: Partial & { + force: boolean; + token: string; +}): Promise> => axios .post( API.POST_MAP, { - title, - address, - route, - stickers, - force, - logo, - distance, - provider, - is_public, - description + route: { + title, + address, + route, + stickers, + logo, + distance, + provider, + is_public, + description + }, + force }, configWithToken(token) ) - .then(result => result && result.data && result.data); + .then(resultMiddleware) + .catch(errorMiddleware); export const checkIframeToken = ({ viewer_id, @@ -150,13 +160,12 @@ export const getRouteList = ({ }>> => axios .get( - API.GET_ROUTE_LIST, + API.GET_ROUTE_LIST(tab), configWithToken(token, { params: { search, min, max, - tab, token, step, shift @@ -199,24 +208,25 @@ export const modifyRoute = ({ }): Promise> => - axios.patch( - API.MODIFY_ROUTE, - { address, token, is_public, title }, - configWithToken(token) - ); - -export const sendRouteStarred = ({ - id, - token, - address, - is_starred -}: { - id: string; - token: string; - address: string; - is_starred: boolean; -}): Promise> => axios - .post(API.SET_STARRED, { id, token, address, is_starred }) + .patch( + API.MODIFY_ROUTE, + { address, token, is_public, title }, + configWithToken(token) + ) + .then(resultMiddleware) + .catch(errorMiddleware); + +export const sendRouteStarred = ({ + token, + address, + is_published +}: { + token: string; + address: string; + is_published: boolean; +}): Promise> => + axios + .post(API.SET_STARRED, { address, is_published }, configWithToken(token)) .then(resultMiddleware) .catch(errorMiddleware);