game/js/registrationTraining/redux/rootReducer.js

30 lines
691 B
JavaScript
Raw Normal View History

2022-12-19 20:22:19 +00:00
import { ALLOW_RENDER, SET_STEP, CLEAN_STATE } from './types.js';
/**
* @param {{ currentStep: Number, isAllowRender: boolean}} state
*/
export const rootReducer = (state, action) => {
const { type, payload } = action;
switch (type) {
case ALLOW_RENDER:
return { ...state, isAllowRender: true };
case SET_STEP:
setStepToLocalStorage(payload);
return { ...state, currentStep: payload };
case CLEAN_STATE:
setStepToLocalStorage(1);
return { ...state, isAllowRender: false, currentStep: 1 };
default:
return state;
}
};
function setStepToLocalStorage(nextStep) {
localStorage.setItem('trainingModalCurrentStep', nextStep);
}