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 { TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE } from './types'; | ||||||
| 
 | 
 | ||||||
| import { tutorials } from '../components/Tutorial/tutorials'; |  | ||||||
| 
 |  | ||||||
| export const tutorialChange = () => (dispatch) => { | export const tutorialChange = () => (dispatch) => { | ||||||
|   dispatch({ |   dispatch({ | ||||||
|     type: TUTORIAL_CHANGE |     type: TUTORIAL_CHANGE | ||||||
| @ -9,16 +7,11 @@ export const tutorialChange = () => (dispatch) => { | |||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| export const tutorialCheck = (id, status) => (dispatch, getState) => { | export const tutorialCheck = (id, status) => (dispatch, getState) => { | ||||||
|   var tutorialsStatus = getState().tutorial.status ? |   var tutorialsStatus = getState().tutorial.status; | ||||||
|                           getState().tutorial.status |   tutorialsStatus[id] = {...tutorialsStatus[id], status: status}; | ||||||
|                         : new Array(tutorials.length).fill({}); |  | ||||||
|   tutorialsStatus[id].status = status; |  | ||||||
|   console.log(tutorials); |  | ||||||
|   dispatch({ |   dispatch({ | ||||||
|     type: status === 'success' ? TUTORIAL_SUCCESS : TUTORIAL_ERROR, |     type: status === 'success' ? TUTORIAL_SUCCESS : TUTORIAL_ERROR, | ||||||
|     payload: tutorialsStatus |     payload: tutorialsStatus | ||||||
|   }); |   }); | ||||||
|   dispatch(tutorialChange()); |   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 { TUTORIAL_SUCCESS, TUTORIAL_ERROR, TUTORIAL_CHANGE } from '../actions/types'; | ||||||
| 
 | 
 | ||||||
|  | import { tutorials } from '../components/Tutorial/tutorials'; | ||||||
| 
 | 
 | ||||||
| const initialState = { | 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 |   change: 0 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| @ -10,6 +13,8 @@ export default function(state = initialState, action){ | |||||||
|   switch(action.type){ |   switch(action.type){ | ||||||
|     case TUTORIAL_SUCCESS: |     case TUTORIAL_SUCCESS: | ||||||
|     case TUTORIAL_ERROR: |     case TUTORIAL_ERROR: | ||||||
|  |       // update locale storage - sync with redux store
 | ||||||
|  |       window.localStorage.setItem('tutorial', JSON.stringify(action.payload)); | ||||||
|       return { |       return { | ||||||
|         ...state, |         ...state, | ||||||
|         status: action.payload |         status: action.payload | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user