diff --git a/src/actions/tutorialActions.js b/src/actions/tutorialActions.js index dd0a5d4..1628154 100644 --- a/src/actions/tutorialActions.js +++ b/src/actions/tutorialActions.js @@ -1,7 +1,5 @@ import { TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE } from './types'; -import { tutorials } from '../components/Tutorial/tutorials'; - export const tutorialChange = () => (dispatch) => { dispatch({ type: TUTORIAL_CHANGE @@ -9,16 +7,11 @@ export const tutorialChange = () => (dispatch) => { }; export const tutorialCheck = (id, status) => (dispatch, getState) => { - var tutorialsStatus = getState().tutorial.status ? - getState().tutorial.status - : new Array(tutorials.length).fill({}); - tutorialsStatus[id].status = status; - console.log(tutorials); + var tutorialsStatus = getState().tutorial.status; + tutorialsStatus[id] = {...tutorialsStatus[id], status: status}; dispatch({ type: status === 'success' ? TUTORIAL_SUCCESS : TUTORIAL_ERROR, payload: tutorialsStatus }); dispatch(tutorialChange()); - // update locale storage - sync with redux store - window.localStorage.setItem('tutorial', JSON.stringify(tutorialsStatus)); }; diff --git a/src/reducers/tutorialReducer.js b/src/reducers/tutorialReducer.js index 327615c..7a9e691 100644 --- a/src/reducers/tutorialReducer.js +++ b/src/reducers/tutorialReducer.js @@ -1,8 +1,11 @@ import { TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE } from '../actions/types'; +import { tutorials } from '../components/Tutorial/tutorials'; const initialState = { - status: JSON.parse(window.localStorage.getItem('tutorial')), + status: window.localStorage.getItem('tutorial') ? + JSON.parse(window.localStorage.getItem('tutorial')) + : new Array(tutorials.length).fill({}), change: 0 }; @@ -10,6 +13,8 @@ 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