redux: half-completed editor panel

This commit is contained in:
muerwre 2018-11-26 14:14:58 +07:00
parent 2656a9fad8
commit e56e49acf4
6 changed files with 67 additions and 24 deletions

View file

@ -10,3 +10,6 @@ export const setActiveSticker = activeSticker => ({ type: ACTIONS.SET_ACTIVE_STI
export const setLogo = logo => ({ type: ACTIONS.SET_LOGO, logo });
export const setTitle = title => ({ type: ACTIONS.SET_TITLE, title });
export const setAddress = address => ({ type: ACTIONS.SET_ADDRESS, address });
export const startEditing = () => ({ type: ACTIONS.START_EDITING });
export const stopEditing = () => ({ type: ACTIONS.STOP_EDITING });

View file

@ -10,4 +10,7 @@ export const ACTIONS = {
SET_LOGO: 'SET_LOGO',
SET_TITLE: 'SET_TITLE',
SET_ADDRESS: 'SET_ADDRESS',
START_EDITING: 'START_EDITING',
STOP_EDITING: 'STOP_EDITING',
};

View file

@ -13,6 +13,7 @@ const setUser = (state, { user }) => ({
});
const setEditing = (state, { editing }) => ({ ...state, editing });
const setChanged = (state, { changed }) => ({ ...state, changed });
const setMode = (state, { mode }) => ({ ...state, mode });
const setDistance = (state, { distance }) => ({ ...state, distance });
const setRouterPoints = (state, { routerPoints }) => ({ ...state, routerPoints });
@ -25,6 +26,7 @@ const setAddress = (state, { address }) => ({ ...state, address });
const HANDLERS = {
[ACTIONS.SET_USER]: setUser,
[ACTIONS.SET_EDITING]: setEditing,
[ACTIONS.SET_CHANGED]: setChanged,
[ACTIONS.SET_MODE]: setMode,
[ACTIONS.SET_DISTANCE]: setDistance,
[ACTIONS.SET_ROUTER_POINTS]: setRouterPoints,

View file

@ -1,12 +1,15 @@
import { REHYDRATE } from 'redux-persist';
import { takeLatest, select, call, put, takeEvery } from 'redux-saga/effects';
import { checkUserToken, getGuestToken, getStoredMap } from '$utils/api';
import { setUser } from '$redux/user/actions';
import { setEditing, setMode, setUser } from '$redux/user/actions';
import { getUrlData, pushPath } from '$utils/history';
import { editor } from '$modules/Editor';
import { ACTIONS } from '$redux/user/constants';
import { MODES } from '$constants/modes';
const getUser = state => (state.user.user);
const getState = state => (state.user);
const hideLoader = () => {
document.getElementById('loader').style.opacity = 0;
document.getElementById('loader').style.pointerEvents = 'none';
@ -79,9 +82,31 @@ function* setModeSaga({ mode }) {
// console.log('change', mode);
}
function* startEditingSaga() {
yield editor.startEditing();
yield put(setEditing(true));
}
function* stopEditingSaga() {
const { changed } = yield select(getState);
if (!changed) {
yield editor.cancelEditing();
yield put(setEditing(false));
yield put(setMode(MODES.NONE));
} else {
// editor.changeMode(MODES.CONFIRM_CANCEL);
// this.props.setMode(MODES.CONFIRM_CANCEL);
yield put(setMode(MODES.CONFIRM_CANCEL));
}
}
export function* userSaga() {
// Login
// yield takeLatest(AUTH_ACTIONS.SEND_LOGIN_REQUEST, sendLoginRequestSaga);
yield takeLatest(REHYDRATE, authChechSaga);
yield takeEvery(ACTIONS.SET_MODE, setModeSaga);
yield takeEvery(ACTIONS.START_EDITING, startEditingSaga);
yield takeEvery(ACTIONS.STOP_EDITING, stopEditingSaga);
}