added map fitting

This commit is contained in:
Fedor Katurov 2020-01-13 17:43:38 +07:00
parent 0314edd550
commit bc34cf3876
12 changed files with 93 additions and 78 deletions

View file

@ -48,7 +48,11 @@ export const editorResetSaveDialog = () => ({ type: EDITOR_ACTIONS.RESET_SAVE_DI
export const editorSetSave = (save: Partial<IEditorState['save']>) => ({
type: EDITOR_ACTIONS.SET_SAVE,
save,
})
});
export const editorCancelSave = () => ({
type: EDITOR_ACTIONS.CANCEL_SAVE,
});
export const editorHideRenderer = () => ({ type: EDITOR_ACTIONS.HIDE_RENDERER });
export const editorSetRenderer = payload => ({ type: EDITOR_ACTIONS.SET_RENDERER, payload });

View file

@ -20,8 +20,8 @@ export const EDITOR_ACTIONS = {
SEND_SAVE_REQUEST: `${P}-SEND_SAVE_REQUEST`,
SET_SAVE_LOADING: `${P}-SET_SAVE_LOADING`,
CANCEL_SAVE_REQUEST: `${P}-CANCEL_SAVE_REQUEST`,
RESET_SAVE_DIALOG: `${P}-RESET_SAVE_DIALOG`,
CANCEL_SAVE: `${P}-CANCEL_SAVE`,
SET_SAVE: `${P}-SET_SAVE`,

View file

@ -51,7 +51,7 @@ export interface IEditorState {
};
}
const EDITOR_INITIAL_STATE = {
export const EDITOR_INITIAL_STATE = {
changed: false,
editing: false,
ready: false,

View file

@ -14,6 +14,7 @@ import {
editorSetFeature,
editorLocationChanged,
editorKeyPressed,
editorSetSave,
} from '~/redux/editor/actions';
import { getUrlData, pushPath } from '~/utils/history';
import { MODES } from '~/constants/modes';
@ -45,6 +46,7 @@ import { MAP_ACTIONS } from '../map/constants';
import { OsrmRouter } from '~/utils/osrm';
import path from 'ramda/es/path';
import { MainMap } from '~/constants/map';
import { EDITOR_INITIAL_STATE } from '.';
const hideLoader = () => {
document.getElementById('loader').style.opacity = String(0);
@ -181,6 +183,7 @@ function* locationChangeSaga({ location }: ReturnType<typeof editorLocationChang
if (!ready) return;
yield call(loadMapFromPath);
MainMap.fitBounds(MainMap.getVisibleBounds(), { animate: true });
}
function* keyPressedSaga({ key, target }: ReturnType<typeof editorKeyPressed>) {
@ -248,6 +251,14 @@ function* routerSubmit() {
yield put(editorSetMode(MODES.NONE));
}
function* cancelSave() {
yield put(
editorSetSave({
...EDITOR_INITIAL_STATE.save,
})
);
}
export function* editorSaga() {
yield takeEvery(EDITOR_ACTIONS.LOCATION_CHANGED, locationChangeSaga);
@ -259,4 +270,5 @@ export function* editorSaga() {
yield takeLatest(EDITOR_ACTIONS.ROUTER_CANCEL, routerCancel);
yield takeLatest(MAP_ACTIONS.MAP_CLICKED, mapClick);
yield takeLatest(EDITOR_ACTIONS.ROUTER_SUBMIT, routerSubmit);
yield takeLatest(EDITOR_ACTIONS.CANCEL_SAVE, cancelSave);
}

View file

@ -39,6 +39,7 @@ import { delay } from 'redux-saga';
import { setReadySaga } from '../editor/sagas';
import { selectEditor } from '../editor/selectors';
import { EDITOR_ACTIONS } from '../editor/constants';
import { MainMap } from '~/constants/map';
function* onMapClick({ latlng }: ReturnType<typeof mapClicked>) {
const {
@ -149,6 +150,7 @@ export function* mapInitSaga() {
yield call(loadMapFromPath);
yield call(setReadySaga);
MainMap.fitBounds(MainMap.getVisibleBounds(), { animate: false });
pushLoaderState(100);
}
@ -234,7 +236,7 @@ function* sendSaveRequestSaga({
const { distance }: ReturnType<typeof selectEditor> = yield select(selectEditor);
const { token }: ReturnType<typeof selectUserUser> = yield select(selectUserUser);
yield put(editorSetSave({ loading: true }));
yield put(editorSetSave({ loading: true, overwriting: false, finished: false, error: null }));
const {
result,
@ -268,6 +270,7 @@ function* sendSaveRequestSaga({
if (result && result.data.code === 'already_exist')
return yield put(editorSetSave({ overwriting: true }));
if (result && result.data.code === 'conflict')
return yield put(
editorSetSave({
@ -277,6 +280,7 @@ function* sendSaveRequestSaga({
finished: false,
})
);
if (timeout || !result || !result.data.route || !result.data.route.address)
return yield put(
editorSetSave({
@ -296,6 +300,10 @@ function* sendSaveRequestSaga({
})
);
yield put(editorSetReady(false));
pushPath(`/${address}/edit`);
yield put(editorSetReady(true));
yield put(
editorSetSave({
error: TIPS.SAVE_SUCCESS,
@ -306,36 +314,6 @@ function* sendSaveRequestSaga({
);
}
// function* setSaveSuccessSaga({
// address,
// title,
// is_public,
// description,
// }: ReturnType<typeof editorSetSaveSuccess>) {
// const { id }: ReturnType<typeof selectUserUser> = yield select(selectUserUser);
// const { dialog_active }: ReturnType<typeof selectEditor> = yield select(selectEditor);
// replacePath(`/${address}/edit`);
// yield put(
// mapSet({
// title,
// address,
// is_public,
// description,
// owner: { id },
// })
// );
// yield put(editorSetChanged(false));
// if (dialog_active) {
// yield call(searchSetSagaWorker);
// }
// return;
// }
export function* mapSaga() {
// TODO: setChanged on set route, logo, provider, stickers
yield takeEvery(EDITOR_ACTIONS.START_EDITING, startEditingSaga);