fixed status update of tutorials
This commit is contained in:
parent
e322795f25
commit
de0bfd5d49
@ -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));
|
||||
};
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user