figure out how redux-thunk works
This commit is contained in:
		
							parent
							
								
									e1a79ba7a6
								
							
						
					
					
						commit
						1045cddaeb
					
				
					 7 changed files with 24 additions and 5 deletions
				
			
		|  | @ -55,6 +55,7 @@ | |||
|     "react-router": "^2.4.1", | ||||
|     "redux": "^3.5.2", | ||||
|     "redux-form": "^5.2.5", | ||||
|     "redux-thunk": "^2.1.0" | ||||
|     "redux-thunk": "^2.1.0", | ||||
|     "shortid": "^2.2.6" | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ export function createProject(req, res) { | |||
| 		}, function(err, newProject) { | ||||
| 			if (err) { return res.json({success: false}) } | ||||
| 			return res.json({ | ||||
| 				id: newProject._id, | ||||
| 				name: newProject.name, | ||||
| 				file: { | ||||
| 					name: newProject.file.name, | ||||
|  |  | |||
|  | @ -1,5 +1,6 @@ | |||
| import mongoose from 'mongoose'; | ||||
| const Schema = mongoose.Schema; | ||||
| import shortid from 'shortid'; | ||||
| 
 | ||||
| const fileSchema = new Schema({ | ||||
| 	name: {type: String, default: 'sketch.js'}, | ||||
|  | @ -9,7 +10,8 @@ const fileSchema = new Schema({ | |||
| const projectSchema = new Schema({ | ||||
| 	name: {type: String, default: "Hello p5.js, it's the server"}, | ||||
| 	user: {type: Schema.Types.ObjectId, ref: 'User'}, | ||||
| 	file: {type: fileSchema} | ||||
| 	file: {type: fileSchema}, | ||||
| 	_id: {type: String, default: shortid.generate} | ||||
| }, {timestamps: true}); | ||||
| 
 | ||||
| export default mongoose.model('Project', projectSchema); | ||||
|  | @ -13,6 +13,8 @@ class IDEView extends React.Component { | |||
| 		return ( | ||||
| 			<div className="ide"> | ||||
| 				<Nav user={this.props.user} | ||||
| 						 project={this.props.project} | ||||
| 						 file={this.props.file} | ||||
| 						 createProject={this.props.createProject} | ||||
| 						 saveProject={this.props.saveProject}/> | ||||
| 				<Toolbar  | ||||
|  |  | |||
|  | @ -66,8 +66,9 @@ export function saveProject() { | |||
| 	// 			type: ActionTypes.PROJECT_SAVE_FAIL
 | ||||
| 	// 		}));
 | ||||
| 	// }
 | ||||
| 	return function(dispatch) { | ||||
| 
 | ||||
| 	return function(dispatch, getState) { | ||||
| 		var state = getState(); | ||||
| 		 | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
|  | @ -78,8 +79,14 @@ export function createProject() { | |||
| 			.then(response => { | ||||
| 				dispatch({ | ||||
| 					type: ActionTypes.NEW_PROJECT, | ||||
| 					name: response.data.name | ||||
| 					name: response.data.name, | ||||
| 					id: response.data.id, | ||||
| 					file: { | ||||
| 						name: response.data.file.name, | ||||
| 						content: response.data.file.content | ||||
| 					} | ||||
| 				}); | ||||
| 				browserHistory.push('/' + response.data.id); | ||||
| 			}) | ||||
| 			.catch(response => dispatch({ | ||||
| 				type: ActionTypes.PROJECT_SAVE_FAIL | ||||
|  |  | |||
|  | @ -18,6 +18,11 @@ const file = (state = initialState, action) => { | |||
| 				name: action.name, | ||||
| 				content: action.content | ||||
| 			} | ||||
| 		case ActionTypes.NEW_PROJECT: | ||||
| 			return { | ||||
| 				name: action.file.name, | ||||
| 				content: action.file.conent | ||||
| 			} | ||||
| 		default: | ||||
| 			return state | ||||
| 	} | ||||
|  |  | |||
|  | @ -12,6 +12,7 @@ const project = (state = initialState, action) => { | |||
| 			} | ||||
| 		case ActionTypes.NEW_PROJECT: | ||||
| 			return { | ||||
| 				id: action.id, | ||||
| 				name: action.name | ||||
| 			} | ||||
| 		default: | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 catarak
						catarak