diff --git a/src/actions/tutorialActions.js b/src/actions/tutorialActions.js new file mode 100644 index 0000000..1628154 --- /dev/null +++ b/src/actions/tutorialActions.js @@ -0,0 +1,17 @@ +import { TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE } from './types'; + +export const tutorialChange = () => (dispatch) => { + dispatch({ + type: TUTORIAL_CHANGE + }); +}; + +export const tutorialCheck = (id, status) => (dispatch, getState) => { + var tutorialsStatus = getState().tutorial.status; + tutorialsStatus[id] = {...tutorialsStatus[id], status: status}; + dispatch({ + type: status === 'success' ? TUTORIAL_SUCCESS : TUTORIAL_ERROR, + payload: tutorialsStatus + }); + dispatch(tutorialChange()); +}; diff --git a/src/reducers/tutorialReducer.js b/src/reducers/tutorialReducer.js new file mode 100644 index 0000000..7a9e691 --- /dev/null +++ b/src/reducers/tutorialReducer.js @@ -0,0 +1,30 @@ +import { TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE } from '../actions/types'; + +import { tutorials } from '../components/Tutorial/tutorials'; + +const initialState = { + status: window.localStorage.getItem('tutorial') ? + JSON.parse(window.localStorage.getItem('tutorial')) + : new Array(tutorials.length).fill({}), + change: 0 +}; + +export default function(state = initialState, action){ + switch(action.type){ + case TUTORIAL_SUCCESS: + case TUTORIAL_ERROR: + // update locale storage - sync with redux store + window.localStorage.setItem('tutorial', JSON.stringify(action.payload)); + return { + ...state, + status: action.payload + }; + case TUTORIAL_CHANGE: + return { + ...state, + change: state.change += 1 + } + default: + return state; + } +}