From 88531447ba3ed10168cb577d61b1c2a829d42042 Mon Sep 17 00:00:00 2001 From: catarak Date: Thu, 7 Jul 2016 13:04:54 -0400 Subject: [PATCH] add ids to files, fix update file action/reducer --- client/modules/IDE/actions/files.js | 2 +- client/modules/IDE/actions/project.js | 2 +- server/models/project.js | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/client/modules/IDE/actions/files.js b/client/modules/IDE/actions/files.js index 40438b1e..3ceca1e1 100644 --- a/client/modules/IDE/actions/files.js +++ b/client/modules/IDE/actions/files.js @@ -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 }; diff --git a/client/modules/IDE/actions/project.js b/client/modules/IDE/actions/project.js index 3f5339d2..8d4e1e56 100644 --- a/client/modules/IDE/actions/project.js +++ b/client/modules/IDE/actions/project.js @@ -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(() => { diff --git a/server/models/project.js b/server/models/project.js index a1306dc7..1ad4b4ee 100644 --- a/server/models/project.js +++ b/server/models/project.js @@ -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 });