add ids to files, fix update file action/reducer
This commit is contained in:
parent
6e12ed6524
commit
88531447ba
3 changed files with 6 additions and 4 deletions
|
@ -2,7 +2,7 @@ import * as ActionTypes from '../../../constants';
|
||||||
|
|
||||||
export function updateFile(name, content) {
|
export function updateFile(name, content) {
|
||||||
return {
|
return {
|
||||||
type: ActionTypes.CHANGE_SELECTED_FILE,
|
type: ActionTypes.UPDATE_FILE,
|
||||||
name,
|
name,
|
||||||
content
|
content
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,7 +34,7 @@ export function saveProject() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
const formParams = Object.assign({}, state.project);
|
const formParams = Object.assign({}, state.project);
|
||||||
formParams.file = state.file;
|
formParams.files = state.files;
|
||||||
if (state.project.id) {
|
if (state.project.id) {
|
||||||
axios.put(`${ROOT_URL}/projects/${state.project.id}`, formParams, { withCredentials: true })
|
axios.put(`${ROOT_URL}/projects/${state.project.id}`, formParams, { withCredentials: true })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
const Schema = mongoose.Schema;
|
const Schema = mongoose.Schema;
|
||||||
|
const ObjectIdSchema = Schema.ObjectId;
|
||||||
|
const ObjectId = mongoose.Types.ObjectId;
|
||||||
import shortid from 'shortid';
|
import shortid from 'shortid';
|
||||||
|
|
||||||
const defaultSketch = `function setup() {
|
const defaultSketch = `function setup() {
|
||||||
|
@ -24,12 +26,12 @@ const defaultHTML =
|
||||||
const fileSchema = new Schema({
|
const fileSchema = new Schema({
|
||||||
name: { type: String, default: 'sketch.js' },
|
name: { type: String, default: 'sketch.js' },
|
||||||
content: { type: String, default: defaultSketch }
|
content: { type: String, default: defaultSketch }
|
||||||
}, { timestamps: true });
|
}, { timestamps: true, _id: true });
|
||||||
|
|
||||||
const projectSchema = new Schema({
|
const projectSchema = new Schema({
|
||||||
name: { type: String, default: "Hello p5.js, it's the server" },
|
name: { type: String, default: "Hello p5.js, it's the server" },
|
||||||
user: { type: Schema.Types.ObjectId, ref: 'User' },
|
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 }
|
_id: { type: String, default: shortid.generate }
|
||||||
}, { timestamps: true });
|
}, { timestamps: true });
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue