add ids to files, fix update file action/reducer

This commit is contained in:
catarak 2016-07-07 13:04:54 -04:00
parent 6e12ed6524
commit 88531447ba
3 changed files with 6 additions and 4 deletions

View file

@ -2,7 +2,7 @@ import * as ActionTypes from '../../../constants';
export function updateFile(name, content) {
return {
type: ActionTypes.CHANGE_SELECTED_FILE,
type: ActionTypes.UPDATE_FILE,
name,
content
};

View file

@ -34,7 +34,7 @@ export function saveProject() {
return (dispatch, getState) => {
const state = getState();
const formParams = Object.assign({}, state.project);
formParams.file = state.file;
formParams.files = state.files;
if (state.project.id) {
axios.put(`${ROOT_URL}/projects/${state.project.id}`, formParams, { withCredentials: true })
.then(() => {

View file

@ -1,5 +1,7 @@
import mongoose from 'mongoose';
const Schema = mongoose.Schema;
const ObjectIdSchema = Schema.ObjectId;
const ObjectId = mongoose.Types.ObjectId;
import shortid from 'shortid';
const defaultSketch = `function setup() {
@ -24,12 +26,12 @@ const defaultHTML =
const fileSchema = new Schema({
name: { type: String, default: 'sketch.js' },
content: { type: String, default: defaultSketch }
}, { timestamps: true });
}, { timestamps: true, _id: true });
const projectSchema = new Schema({
name: { type: String, default: "Hello p5.js, it's the server" },
user: { type: Schema.Types.ObjectId, ref: 'User' },
files: {type: [ fileSchema ], default: [{ name: 'sketch.js', content: defaultSketch }, { name: 'index.html', content: defaultHTML }]},
files: {type: [ fileSchema ], default: [{ name: 'sketch.js', content: defaultSketch, _id: new ObjectId() }, { name: 'index.html', content: defaultHTML, _id: new ObjectId() }]},
_id: { type: String, default: shortid.generate }
}, { timestamps: true });