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
This commit is contained in:
Cassie Tarakajian 2019-04-24 13:32:23 -04:00 committed by GitHub
parent c3de0512cc
commit 8b296a51aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import blobUtil from 'blob-util';
import { reset } from 'redux-form'; import { reset } from 'redux-form';
import * as ActionTypes from '../../../constants'; import * as ActionTypes from '../../../constants';
import { setUnsavedChanges } from './ide'; import { setUnsavedChanges } from './ide';
import { setProjectSavedTime } from './project';
const __process = (typeof global !== 'undefined' ? global : window).process; const __process = (typeof global !== 'undefined' ? global : window).process;
const ROOT_URL = __process.env.API_URL; const ROOT_URL = __process.env.API_URL;
@ -60,9 +61,10 @@ export function createFile(formProps) {
.then((response) => { .then((response) => {
dispatch({ dispatch({
type: ActionTypes.CREATE_FILE, type: ActionTypes.CREATE_FILE,
...response.data, ...response.data.updatedFile,
parentId parentId
}); });
dispatch(setProjectSavedTime(response.data.project.updatedAt));
dispatch(reset('new-file')); dispatch(reset('new-file'));
// dispatch({ // dispatch({
// type: ActionTypes.HIDE_MODAL // type: ActionTypes.HIDE_MODAL
@ -117,9 +119,10 @@ export function createFolder(formProps) {
.then((response) => { .then((response) => {
dispatch({ dispatch({
type: ActionTypes.CREATE_FILE, type: ActionTypes.CREATE_FILE,
...response.data, ...response.data.updatedFile,
parentId parentId
}); });
dispatch(setProjectSavedTime(response.data.project.updatedAt));
dispatch({ dispatch({
type: ActionTypes.CLOSE_NEW_FOLDER_MODAL type: ActionTypes.CLOSE_NEW_FOLDER_MODAL
}); });

View file

@ -328,3 +328,10 @@ export function hideEditProjectName() {
type: ActionTypes.HIDE_EDIT_PROJECT_NAME type: ActionTypes.HIDE_EDIT_PROJECT_NAME
}; };
} }
export function setProjectSavedTime(updatedAt) {
return {
type: ActionTypes.SET_PROJECT_SAVED_TIME,
value: updatedAt
};
}

View file

@ -28,13 +28,18 @@ export function createFile(req, res) {
} }
const newFile = updatedProject.files[updatedProject.files.length - 1]; const newFile = updatedProject.files[updatedProject.files.length - 1];
updatedProject.files.id(req.body.parentId).children.push(newFile.id); updatedProject.files.id(req.body.parentId).children.push(newFile.id);
updatedProject.save((innerErr) => { updatedProject.save((innerErr, savedProject) => {
if (innerErr) { if (innerErr) {
console.log(innerErr); console.log(innerErr);
res.json({ success: false }); res.json({ success: false });
return; 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
});
});
}); });
} }
); );