From 8b296a51aac7dea3eb8f21eb21d7a689eea31428 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Wed, 24 Apr 2019 13:32:23 -0400 Subject: [PATCH] Fixes #1052, in which you can't save a sketch after uploading a file (#1053) Fixes #1052, in which a user can't save a sketch after uploading a file --- client/modules/IDE/actions/files.js | 7 +++++-- client/modules/IDE/actions/project.js | 7 +++++++ server/controllers/file.controller.js | 9 +++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/client/modules/IDE/actions/files.js b/client/modules/IDE/actions/files.js index 7e9a8c80..ff56454a 100644 --- a/client/modules/IDE/actions/files.js +++ b/client/modules/IDE/actions/files.js @@ -4,6 +4,7 @@ import blobUtil from 'blob-util'; import { reset } from 'redux-form'; import * as ActionTypes from '../../../constants'; import { setUnsavedChanges } from './ide'; +import { setProjectSavedTime } from './project'; const __process = (typeof global !== 'undefined' ? global : window).process; const ROOT_URL = __process.env.API_URL; @@ -60,9 +61,10 @@ export function createFile(formProps) { .then((response) => { dispatch({ type: ActionTypes.CREATE_FILE, - ...response.data, + ...response.data.updatedFile, parentId }); + dispatch(setProjectSavedTime(response.data.project.updatedAt)); dispatch(reset('new-file')); // dispatch({ // type: ActionTypes.HIDE_MODAL @@ -117,9 +119,10 @@ export function createFolder(formProps) { .then((response) => { dispatch({ type: ActionTypes.CREATE_FILE, - ...response.data, + ...response.data.updatedFile, parentId }); + dispatch(setProjectSavedTime(response.data.project.updatedAt)); dispatch({ type: ActionTypes.CLOSE_NEW_FOLDER_MODAL }); diff --git a/client/modules/IDE/actions/project.js b/client/modules/IDE/actions/project.js index b04da7a5..355faecf 100644 --- a/client/modules/IDE/actions/project.js +++ b/client/modules/IDE/actions/project.js @@ -328,3 +328,10 @@ export function hideEditProjectName() { type: ActionTypes.HIDE_EDIT_PROJECT_NAME }; } + +export function setProjectSavedTime(updatedAt) { + return { + type: ActionTypes.SET_PROJECT_SAVED_TIME, + value: updatedAt + }; +} diff --git a/server/controllers/file.controller.js b/server/controllers/file.controller.js index a281f725..69625a18 100644 --- a/server/controllers/file.controller.js +++ b/server/controllers/file.controller.js @@ -28,13 +28,18 @@ export function createFile(req, res) { } const newFile = updatedProject.files[updatedProject.files.length - 1]; updatedProject.files.id(req.body.parentId).children.push(newFile.id); - updatedProject.save((innerErr) => { + updatedProject.save((innerErr, savedProject) => { if (innerErr) { console.log(innerErr); res.json({ success: false }); return; } - res.json(updatedProject.files[updatedProject.files.length - 1]); + savedProject.populate({ path: 'user', select: 'username' }, (_, populatedProject) => { + res.json({ + updatedFile: updatedProject.files[updatedProject.files.length - 1], + project: populatedProject + }); + }); }); } );