redux store of builder
This commit is contained in:
		
							parent
							
								
									1c2b025493
								
							
						
					
					
						commit
						458770e0c4
					
				
							
								
								
									
										83
									
								
								src/actions/tutorialBuilderActions.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										83
									
								
								src/actions/tutorialBuilderActions.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,83 @@ | |||||||
|  | import { BUILDER_CHANGE, BUILDER_TITLE, BUILDER_ID, BUILDER_ADD_STEP, BUILDER_DELETE_STEP, BUILDER_CHANGE_STEP, BUILDER_CHANGE_ORDER, BUILDER_DELETE_PROPERTY } from './types'; | ||||||
|  | 
 | ||||||
|  | export const changeTutorialBuilder = () => (dispatch) => { | ||||||
|  |   dispatch({ | ||||||
|  |     type: BUILDER_CHANGE | ||||||
|  |   }); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export const tutorialTitle = (title) => (dispatch) => { | ||||||
|  |   dispatch({ | ||||||
|  |     type: BUILDER_TITLE, | ||||||
|  |     payload: title | ||||||
|  |   }); | ||||||
|  |   dispatch(changeTutorialBuilder()); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export const tutorialId = (id) => (dispatch) => { | ||||||
|  |   dispatch({ | ||||||
|  |     type: BUILDER_ID, | ||||||
|  |     payload: id | ||||||
|  |   }); | ||||||
|  |   dispatch(changeTutorialBuilder()); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export const addStep = (index) => (dispatch, getState) => { | ||||||
|  |   var steps = getState().builder.steps; | ||||||
|  |   var step = { | ||||||
|  |     id: index+1, | ||||||
|  |     type: 'instruction', | ||||||
|  |     headline: '', | ||||||
|  |     text: '' | ||||||
|  |   }; | ||||||
|  |   steps.splice(index, 0, step); | ||||||
|  |   dispatch({ | ||||||
|  |     type: BUILDER_ADD_STEP, | ||||||
|  |     payload: steps | ||||||
|  |   }); | ||||||
|  |   dispatch(changeTutorialBuilder()); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export const removeStep = (index) => (dispatch, getState) => { | ||||||
|  |   var steps = getState().builder.steps; | ||||||
|  |   steps.splice(index, 1); | ||||||
|  |   dispatch({ | ||||||
|  |     type: BUILDER_DELETE_STEP, | ||||||
|  |     payload: steps | ||||||
|  |   }); | ||||||
|  |   dispatch(changeTutorialBuilder()); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export const changeContent = (index, property, content) => (dispatch, getState) => { | ||||||
|  |   var steps = getState().builder.steps; | ||||||
|  |   var step = steps[index]; | ||||||
|  |   step[property] = content; | ||||||
|  |   dispatch({ | ||||||
|  |     type: BUILDER_CHANGE_STEP, | ||||||
|  |     payload: steps | ||||||
|  |   }); | ||||||
|  |   dispatch(changeTutorialBuilder()); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export const deleteProperty = (index, property) => (dispatch, getState) => { | ||||||
|  |   var steps = getState().builder.steps; | ||||||
|  |   var step = steps[index]; | ||||||
|  |   delete step[property]; | ||||||
|  |   dispatch({ | ||||||
|  |     type: BUILDER_DELETE_PROPERTY, | ||||||
|  |     payload: steps | ||||||
|  |   }); | ||||||
|  |   dispatch(changeTutorialBuilder()); | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export const changeStepIndex = (fromIndex, toIndex) => (dispatch, getState) => { | ||||||
|  |   var steps = getState().builder.steps; | ||||||
|  |   var step = steps[fromIndex]; | ||||||
|  |   steps.splice(fromIndex, 1); | ||||||
|  |   steps.splice(toIndex, 0, step); | ||||||
|  |   dispatch({ | ||||||
|  |     type: BUILDER_CHANGE_ORDER, | ||||||
|  |     payload: steps | ||||||
|  |   }); | ||||||
|  |   dispatch(changeTutorialBuilder()); | ||||||
|  | }; | ||||||
| @ -14,3 +14,13 @@ export const TUTORIAL_CHANGE = 'TUTORIAL_CHANGE'; | |||||||
| export const TUTORIAL_XML = 'TUTORIAL_XML'; | export const TUTORIAL_XML = 'TUTORIAL_XML'; | ||||||
| export const TUTORIAL_ID = 'TUTORIAL_ID'; | export const TUTORIAL_ID = 'TUTORIAL_ID'; | ||||||
| export const TUTORIAL_STEP = 'TUTORIAL_STEP'; | export const TUTORIAL_STEP = 'TUTORIAL_STEP'; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | export const BUILDER_CHANGE = 'BUILDER_CHANGE'; | ||||||
|  | export const BUILDER_TITLE = 'BUILDER_TITLE'; | ||||||
|  | export const BUILDER_ID = 'BUILDER_ID'; | ||||||
|  | export const BUILDER_ADD_STEP = 'BUILDER_ADD_STEP'; | ||||||
|  | export const BUILDER_DELETE_STEP = 'BUILDER_DELETE_STEP'; | ||||||
|  | export const BUILDER_CHANGE_STEP = 'BUILDER_CHANGE_STEP'; | ||||||
|  | export const BUILDER_CHANGE_ORDER = 'BUILDER_CHANGE_ORDER'; | ||||||
|  | export const BUILDER_DELETE_PROPERTY = 'BUILDER_DELETE_PROPERTY'; | ||||||
|  | |||||||
| @ -1,8 +1,10 @@ | |||||||
| import { combineReducers } from 'redux'; | import { combineReducers } from 'redux'; | ||||||
| import workspaceReducer from './workspaceReducer'; | import workspaceReducer from './workspaceReducer'; | ||||||
| import tutorialReducer from './tutorialReducer'; | import tutorialReducer from './tutorialReducer'; | ||||||
|  | import tutorialBuilderReducer from './tutorialBuilderReducer'; | ||||||
| 
 | 
 | ||||||
| export default combineReducers({ | export default combineReducers({ | ||||||
|   workspace: workspaceReducer, |   workspace: workspaceReducer, | ||||||
|   tutorial: tutorialReducer |   tutorial: tutorialReducer, | ||||||
|  |   builder: tutorialBuilderReducer | ||||||
| }); | }); | ||||||
|  | |||||||
							
								
								
									
										48
									
								
								src/reducers/tutorialBuilderReducer.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								src/reducers/tutorialBuilderReducer.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,48 @@ | |||||||
|  | import { BUILDER_CHANGE, BUILDER_TITLE, BUILDER_ID, BUILDER_ADD_STEP, BUILDER_DELETE_STEP, BUILDER_CHANGE_STEP,BUILDER_CHANGE_ORDER, BUILDER_DELETE_PROPERTY } from '../actions/types'; | ||||||
|  | 
 | ||||||
|  | const initialState = { | ||||||
|  |   change: 0, | ||||||
|  |   title: '', | ||||||
|  |   id: 0, | ||||||
|  |   steps: [ | ||||||
|  |     { | ||||||
|  |       id: 1, | ||||||
|  |       type: 'instruction', | ||||||
|  |       headline: '', | ||||||
|  |       text: '', | ||||||
|  |       hardware: [], | ||||||
|  |       requirements: [] | ||||||
|  |     } | ||||||
|  |   ] | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | export default function(state = initialState, action){ | ||||||
|  |   switch(action.type){ | ||||||
|  |     case BUILDER_CHANGE: | ||||||
|  |       return { | ||||||
|  |         ...state, | ||||||
|  |         change: state.change += 1 | ||||||
|  |       }; | ||||||
|  |     case BUILDER_TITLE: | ||||||
|  |       return { | ||||||
|  |         ...state, | ||||||
|  |         title: action.payload | ||||||
|  |       }; | ||||||
|  |     case BUILDER_ID: | ||||||
|  |       return { | ||||||
|  |         ...state, | ||||||
|  |         id: action.payload | ||||||
|  |       }; | ||||||
|  |     case BUILDER_ADD_STEP: | ||||||
|  |     case BUILDER_DELETE_STEP: | ||||||
|  |     case BUILDER_CHANGE_STEP: | ||||||
|  |     case BUILDER_CHANGE_ORDER: | ||||||
|  |     case BUILDER_DELETE_PROPERTY: | ||||||
|  |       return { | ||||||
|  |         ...state, | ||||||
|  |         steps: action.payload | ||||||
|  |       }; | ||||||
|  |     default: | ||||||
|  |       return state; | ||||||
|  |   } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user