Merge branch 'tutorial' into assessment
This commit is contained in:
commit
e766b05dba
17
src/actions/tutorialActions.js
Normal file
17
src/actions/tutorialActions.js
Normal 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());
|
||||
};
|
30
src/reducers/tutorialReducer.js
Normal file
30
src/reducers/tutorialReducer.js
Normal 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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user