redux: editor-panel: login-logout

This commit is contained in:
muerwre 2018-11-26 15:11:51 +07:00
parent e56e49acf4
commit 185fe80fc5
15 changed files with 314 additions and 260 deletions

View file

@ -1,6 +1,9 @@
import { ACTIONS } from '$redux/user/constants';
export const setUser = user => ({ type: ACTIONS.SET_USER, user });
export const userLogout = user => ({ type: ACTIONS.USER_LOGOUT });
export const setEditing = editing => ({ type: ACTIONS.SET_EDITING, editing });
export const setMode = mode => ({ type: ACTIONS.SET_MODE, mode });
export const setDistance = distance => ({ type: ACTIONS.SET_DISTANCE, distance });

View file

@ -1,7 +1,8 @@
export const ACTIONS = {
SET_USER: 'SET_USER',
SET_EDITING: 'SET_EDITING',
USER_LOGOUT: 'USER_LOGOUT',
SET_EDITING: 'SET_EDITING',
SET_MODE: 'SET_MODE',
SET_DISTANCE: 'SET_DISTANCE',
SET_CHANGED: 'SET_CHANGED',

View file

@ -6,6 +6,7 @@ import { getUrlData, pushPath } from '$utils/history';
import { editor } from '$modules/Editor';
import { ACTIONS } from '$redux/user/constants';
import { MODES } from '$constants/modes';
import { DEFAULT_USER } from '$constants/auth';
const getUser = state => (state.user.user);
const getState = state => (state.user);
@ -101,12 +102,40 @@ function* stopEditingSaga() {
}
}
function* userLogoutSaga() {
const { id } = yield select(getUser);
if (id === editor.owner) {
editor.owner = null;
}
yield put(setUser(DEFAULT_USER));
yield call(generateGuestSaga);
}
function* setActiveStickerSaga({ activeSticker }) {
yield editor.activeSticker = activeSticker;
return true;
}
function* setLogoSaga({ logo }) {
const { mode } = yield select(getState);
editor.logo = logo;
if (mode === MODES.LOGO) {
yield put(setMode(MODES.NONE));
}
}
export function* userSaga() {
// Login
// yield takeLatest(AUTH_ACTIONS.SEND_LOGIN_REQUEST, sendLoginRequestSaga);
// ASYNCHRONOUS!!! :-)
yield takeLatest(REHYDRATE, authChechSaga);
yield takeEvery(ACTIONS.SET_MODE, setModeSaga);
yield takeEvery(ACTIONS.START_EDITING, startEditingSaga);
yield takeEvery(ACTIONS.STOP_EDITING, stopEditingSaga);
yield takeEvery(ACTIONS.USER_LOGOUT, userLogoutSaga);
yield takeEvery(ACTIONS.SET_ACTIVE_STICKER, setActiveStickerSaga);
yield takeEvery(ACTIONS.SET_LOGO, setLogoSaga);
}