diff --git a/client/modules/IDE/actions/files.js b/client/modules/IDE/actions/files.js index 60b31e3b..86dde601 100644 --- a/client/modules/IDE/actions/files.js +++ b/client/modules/IDE/actions/files.js @@ -71,7 +71,7 @@ export function getBlobUrl(file) { export function createFile(formProps) { return (dispatch, getState) => { const state = getState(); - const selectedFile = state.files.find(file => file.isSelected); + const selectedFile = state.files.find(file => file.isSelectedFile); const rootFile = state.files.find(file => file.name === 'root'); let parentId; if (selectedFile.fileType === 'folder') { @@ -130,7 +130,7 @@ export function createFile(formProps) { export function createFolder(formProps) { return (dispatch, getState) => { const state = getState(); - const selectedFile = state.files.find(file => file.isSelected); + const selectedFile = state.files.find(file => file.isSelectedFile); const rootFile = state.files.find(file => file.name === 'root'); let parentId; if (selectedFile.fileType === 'folder') { diff --git a/client/modules/IDE/actions/uploader.js b/client/modules/IDE/actions/uploader.js index 0854a040..23e10b9e 100644 --- a/client/modules/IDE/actions/uploader.js +++ b/client/modules/IDE/actions/uploader.js @@ -2,7 +2,6 @@ import axios from 'axios'; import { createFile } from './files'; const textFileRegex = /text\//; -const s3Bucket = `http://${process.env.S3_BUCKET}.s3.amazonaws.com/`; const s3BucketHttps = `https://s3-us-west-2.amazonaws.com/${process.env.S3_BUCKET}/`; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api'; diff --git a/client/modules/IDE/components/FileNode.js b/client/modules/IDE/components/FileNode.js index 48651984..b2d7c1f2 100644 --- a/client/modules/IDE/components/FileNode.js +++ b/client/modules/IDE/components/FileNode.js @@ -60,7 +60,7 @@ export class FileNode extends React.Component { let itemClass = classNames({ 'sidebar__root-item': this.props.name === 'root', 'sidebar__file-item': this.props.name !== 'root', - 'sidebar__file-item--selected': this.props.isSelected, + 'sidebar__file-item--selected': this.props.isSelectedFile, 'sidebar__file-item--open': this.props.isOptionsOpen, 'sidebar__file-item--editing': this.props.isEditingName, 'sidebar__file-item--closed': this.props.isFolderClosed @@ -198,7 +198,7 @@ FileNode.propTypes = { children: PropTypes.array, name: PropTypes.string.isRequired, fileType: PropTypes.string.isRequired, - isSelected: PropTypes.bool, + isSelectedFile: PropTypes.bool, isOptionsOpen: PropTypes.bool, isEditingName: PropTypes.bool, isFolderClosed: PropTypes.bool, diff --git a/client/modules/IDE/components/SidebarItem.js b/client/modules/IDE/components/SidebarItem.js index ac9a6490..bba03a74 100644 --- a/client/modules/IDE/components/SidebarItem.js +++ b/client/modules/IDE/components/SidebarItem.js @@ -35,7 +35,7 @@ class SidebarItem extends React.Component { render() { let itemClass = classNames({ 'sidebar__file-item': true, - 'sidebar__file-item--selected': this.props.file.isSelected, + 'sidebar__file-item--selected': this.props.file.isSelectedFile, 'sidebar__file-item--open': this.props.file.isOptionsOpen, 'sidebar__file-item--editing': this.props.file.isEditingName }); @@ -106,7 +106,7 @@ SidebarItem.propTypes = { file: PropTypes.shape({ id: PropTypes.string.isRequired, name: PropTypes.string.isRequired, - isSelected: PropTypes.bool, + isSelectedFile: PropTypes.bool, isOptionsOpen: PropTypes.bool, isEditingName: PropTypes.bool }).isRequired, diff --git a/client/modules/IDE/pages/IDEView.js b/client/modules/IDE/pages/IDEView.js index f7b77a54..d0aa17ae 100644 --- a/client/modules/IDE/pages/IDEView.js +++ b/client/modules/IDE/pages/IDEView.js @@ -462,7 +462,7 @@ IDEView.propTypes = { function mapStateToProps(state) { return { files: state.files, - selectedFile: state.files.filter(file => file.isSelected)[0], + selectedFile: state.files.filter(file => file.isSelectedFile)[0], htmlFile: getHTMLFile(state.files), jsFiles: getJSFiles(state.files), cssFiles: getCSSFiles(state.files), diff --git a/client/modules/IDE/reducers/files.js b/client/modules/IDE/reducers/files.js index 20302063..27cd527c 100644 --- a/client/modules/IDE/reducers/files.js +++ b/client/modules/IDE/reducers/files.js @@ -50,7 +50,7 @@ function initialState() { content: defaultSketch, id: a, _id: a, - isSelected: true, + isSelectedFile: true, fileType: 'file', children: [] }, @@ -207,9 +207,9 @@ const files = (state, action) => { case ActionTypes.SET_SELECTED_FILE: return state.map(file => { if (file.id === action.selectedFile) { - return Object.assign({}, file, { isSelected: true }); + return Object.assign({}, file, { isSelectedFile: true }); } - return Object.assign({}, file, { isSelected: false }); + return Object.assign({}, file, { isSelectedFile: false }); }); case ActionTypes.SHOW_FOLDER_CHILDREN: return state.map(file => { diff --git a/server/models/project.js b/server/models/project.js index 9fd8bffa..0df2c932 100644 --- a/server/models/project.js +++ b/server/models/project.js @@ -39,7 +39,7 @@ const fileSchema = new Schema({ url: { type: String }, children: { type: [ String ], default: [] }, fileType: { type: String, default: 'file' }, - isSelected: { type: Boolean } + isSelectedFile: { type: Boolean } }, { timestamps: true, _id: true }); fileSchema.virtual('id').get(function(){ @@ -71,7 +71,7 @@ projectSchema.set('toJSON', { // let a = new ObjectId(); // let b = new ObjectId(); // let c = new ObjectId(); -// project.files = [{ name: 'sketch.js', content: defaultSketch, _id: a, isSelected: true }, +// project.files = [{ name: 'sketch.js', content: defaultSketch, _id: a, isSelectedFile: true }, // { name: 'index.html', content: defaultHTML, _id: b }, // { name: 'style.css', content: defaultCSS, _id: c }, // { name: 'root', _id: new ObjectId(), children: [a, b, c] }]; diff --git a/server/utils/db_reformat.js b/server/utils/db_reformat.js index cdc9c2b2..cded9f5d 100644 --- a/server/utils/db_reformat.js +++ b/server/utils/db_reformat.js @@ -64,17 +64,32 @@ import Project from '../models/project'; // }); // }); -const s3Bucket = `http://p5.js-webeditor.s3.amazonaws.com/`; -const s3BucketHttps = `https://s3-us-west-2.amazonaws.com/p5.js-webeditor/`; +// const s3Bucket = `http://p5.js-webeditor.s3.amazonaws.com/`; +// const s3BucketHttps = `https://s3-us-west-2.amazonaws.com/p5.js-webeditor/`; + +// Project.find({}) +// .exec((err, projects) => { +// projects.forEach((project, projectIndex) => { +// project.files.forEach((file) => { +// if (file.url) { +// file.url = file.url.replace(s3Bucket, s3BucketHttps); +// console.log('Updating', file.name); +// console.log(file.url); +// } +// }); +// project.save((err, savedProject) => { +// console.log('project', projectIndex, 'is saved.'); +// }); +// }); +// }); Project.find({}) .exec((err, projects) => { projects.forEach((project, projectIndex) => { project.files.forEach((file) => { - if (file.url) { - file.url = file.url.replace(s3Bucket, s3BucketHttps); - console.log('Updating', file.name); - console.log(file.url); + if (file.isSelected === true || file.isSelected === false) { + file.isSelectedFile = file.isSelected; + delete file.isSelected; } }); project.save((err, savedProject) => {