osrm service checking

This commit is contained in:
muerwre 2019-03-05 16:48:30 +07:00
parent 143f3107e1
commit 9744b0dfd5
8 changed files with 74 additions and 29 deletions

View file

@ -68,3 +68,5 @@ export const setIsEmpty = is_empty => ({ type: ACTIONS.SET_IS_EMPTY, is_empty })
export const mapsLoadMore = () => ({ type: ACTIONS.MAPS_LOAD_MORE });
export const mapsSetShift = (shift: number) => ({ type: ACTIONS.MAPS_SET_SHIFT, shift });
export const setFeature = (features: { [x: string]: boolean }) => ({ type: ACTIONS.SET_FEATURE, features });

View file

@ -75,4 +75,6 @@ export const ACTIONS: IActions = {
MAPS_LOAD_MORE: 'MAPS_LOAD_MORE',
MAPS_SET_SHIFT: 'MAPS_SET_SHIFT',
SET_FEATURE: 'SET_FEATURE',
};

View file

@ -46,6 +46,10 @@ export interface IRootReducer {
dialog: IDialogs[keyof IDialogs],
dialog_active: boolean,
features: {
routing: boolean,
},
renderer: {
data: string,
width: number,
@ -285,6 +289,14 @@ const mapsSetShift: ActionHandler<typeof ActionCreators.mapsSetShift> = (state,
}
});
const setFeature: ActionHandler<typeof ActionCreators.setFeature> = (state, { features }) => ({
...state,
features: {
...state.features,
...features,
}
});
const HANDLERS = ({
[ACTIONS.SET_USER]: setUser,
[ACTIONS.SET_EDITING]: setEditing,
@ -327,6 +339,7 @@ const HANDLERS = ({
[ACTIONS.SET_IS_EMPTY]: setIsEmpty,
[ACTIONS.MAPS_SET_SHIFT]: mapsSetShift,
[ACTIONS.SET_FEATURE]: setFeature,
});
export const INITIAL_STATE: IRootReducer = {
@ -358,6 +371,10 @@ export const INITIAL_STATE: IRootReducer = {
dialog: DIALOGS.NONE,
dialog_active: false,
features: {
routing: false,
},
renderer: {
data: '',
width: 0,

View file

@ -2,7 +2,7 @@ import { REHYDRATE } from 'redux-persist';
import { delay, SagaIterator } from 'redux-saga';
import { takeLatest, select, call, put, takeEvery, race, take } from 'redux-saga/effects';
import {
checkIframeToken,
checkIframeToken, checkOSRMService,
checkUserToken,
getGuestToken, getRouteList,
getStoredMap,
@ -32,7 +32,7 @@ import {
setProvider,
changeProvider,
setSaveLoading,
mapsSetShift, searchChangeDistance, clearAll,
mapsSetShift, searchChangeDistance, clearAll, setFeature,
} from '$redux/user/actions';
import { getUrlData, parseQuery, pushLoaderState, pushNetworkInitError, pushPath, replacePath } from '$utils/history';
import { editor } from '$modules/Editor';
@ -85,7 +85,7 @@ function* startEmptyEditorSaga() {
yield put(setChanged(false));
yield put(setEditing(true));
return hideLoader();
return yield call(setReadySaga);
}
function* startEditingSaga() {
@ -136,6 +136,21 @@ function* replaceAddressIfItsBusy(destination, original) {
pushPath(`/${destination}/edit`);
}
function* checkOSRMServiceSaga() {
const north_east = editor.map.map.getBounds().getNorthEast();
const south_west = editor.map.map.getBounds().getSouthWest();
const routing = yield call(checkOSRMService, [north_east, south_west]);
yield put(setFeature({ routing }));
}
function* setReadySaga() {
yield put(setReady(true));
hideLoader();
yield call(checkOSRMServiceSaga);
}
function* mapInitSaga() {
pushLoaderState(90);
@ -150,9 +165,7 @@ function* mapInitSaga() {
if (newUrl) {
yield pushPath(`/${newUrl}`);
yield put(setReady(true));
hideLoader();
return;
return yield call(setReadySaga);
}
}
@ -162,7 +175,7 @@ function* mapInitSaga() {
if (map) {
if (mode && mode === 'edit') {
if (map && map.owner && mode === 'edit' && map.owner.id !== id) {
hideLoader();
yield call(setReadySaga);
yield call(replaceAddressIfItsBusy, map.random_url, map.address);
} else {
yield put(setAddressOrigin(''));
@ -175,8 +188,7 @@ function* mapInitSaga() {
editor.stopEditing();
}
yield put(setReady(true));
hideLoader();
yield call(setReadySaga);
return true;
}
}