modified to match golang backend

This commit is contained in:
Fedor Katurov 2019-12-12 17:22:57 +07:00
parent 62cb8d8e18
commit 2144af9899
13 changed files with 296 additions and 235 deletions

View file

@ -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 });

View file

@ -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<typeof ActionCreators.searchSetTab> = (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<typeof ActionCreators.searchSetLoading> =
});
const setPublic: ActionHandler<typeof ActionCreators.setPublic> = (state, { is_public = false }) => ({ ...state, is_public });
const setStarred: ActionHandler<typeof ActionCreators.setStarred> = (state, { is_starred = false }) => ({ ...state, is_starred });
const setStarred: ActionHandler<typeof ActionCreators.setStarred> = (state, { is_published = false }) => ({ ...state, is_published });
const setSpeed: ActionHandler<typeof ActionCreators.setSpeed> = (state, { speed = 15 }) => ({
...state,
@ -335,16 +335,16 @@ const setIsRouting: ActionHandler<typeof ActionCreators.setIsRouting> = (state,
is_routing,
});
const setRouteStarred: ActionHandler<typeof ActionCreators.setRouteStarred> = (state, { address, is_starred }) => ({
const setRouteStarred: ActionHandler<typeof ActionCreators.setRouteStarred> = (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,

View file

@ -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<typeof getStoredMap> = yield call(getStoredMap, { name: path });
const {
data: { route, error, random_url }
}: Unwrap<typeof getStoredMap> = 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<typeof getRouteList> = 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() {