current tutorial id stored in redux store

This commit is contained in:
Delucse
2020-09-08 13:42:55 +02:00
parent c1d3962fb4
commit 7e0fbf1f75
9 changed files with 214 additions and 127 deletions
+8 -1
View File
@@ -1,4 +1,4 @@
import { TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE } from '../actions/types';
import { TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE, TUTORIAL_XML, TUTORIAL_ID } from '../actions/types';
import { tutorials } from '../components/Tutorial/tutorials';
@@ -6,6 +6,7 @@ const initialState = {
status: window.localStorage.getItem('tutorial') ?
JSON.parse(window.localStorage.getItem('tutorial'))
: new Array(tutorials.length).fill({}),
currentId: null,
change: 0
};
@@ -13,6 +14,7 @@ export default function(state = initialState, action){
switch(action.type){
case TUTORIAL_SUCCESS:
case TUTORIAL_ERROR:
case TUTORIAL_XML:
// update locale storage - sync with redux store
window.localStorage.setItem('tutorial', JSON.stringify(action.payload));
return {
@@ -24,6 +26,11 @@ export default function(state = initialState, action){
...state,
change: state.change += 1
}
case TUTORIAL_ID:
return {
...state,
currentId: action.payload
}
default:
return state;
}