Merge branch 'tutorial' into assessment

This commit is contained in:
Delucse 2020-09-08 11:56:09 +02:00
commit e766b05dba
2 changed files with 47 additions and 0 deletions

View File

@ -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());
};

View File

@ -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;
}
}