change isSelected to isSelectedFile, add db reformat

This commit is contained in:
catarak 2016-09-14 15:57:52 -04:00
parent 2d4cb76edf
commit 9e6d4b56bd
8 changed files with 33 additions and 19 deletions

View file

@ -71,7 +71,7 @@ export function getBlobUrl(file) {
export function createFile(formProps) { export function createFile(formProps) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = 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'); const rootFile = state.files.find(file => file.name === 'root');
let parentId; let parentId;
if (selectedFile.fileType === 'folder') { if (selectedFile.fileType === 'folder') {
@ -130,7 +130,7 @@ export function createFile(formProps) {
export function createFolder(formProps) { export function createFolder(formProps) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = 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'); const rootFile = state.files.find(file => file.name === 'root');
let parentId; let parentId;
if (selectedFile.fileType === 'folder') { if (selectedFile.fileType === 'folder') {

View file

@ -2,7 +2,6 @@ import axios from 'axios';
import { createFile } from './files'; import { createFile } from './files';
const textFileRegex = /text\//; 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 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'; const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';

View file

@ -60,7 +60,7 @@ export class FileNode extends React.Component {
let itemClass = classNames({ let itemClass = classNames({
'sidebar__root-item': this.props.name === 'root', 'sidebar__root-item': this.props.name === 'root',
'sidebar__file-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--open': this.props.isOptionsOpen,
'sidebar__file-item--editing': this.props.isEditingName, 'sidebar__file-item--editing': this.props.isEditingName,
'sidebar__file-item--closed': this.props.isFolderClosed 'sidebar__file-item--closed': this.props.isFolderClosed
@ -198,7 +198,7 @@ FileNode.propTypes = {
children: PropTypes.array, children: PropTypes.array,
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
fileType: PropTypes.string.isRequired, fileType: PropTypes.string.isRequired,
isSelected: PropTypes.bool, isSelectedFile: PropTypes.bool,
isOptionsOpen: PropTypes.bool, isOptionsOpen: PropTypes.bool,
isEditingName: PropTypes.bool, isEditingName: PropTypes.bool,
isFolderClosed: PropTypes.bool, isFolderClosed: PropTypes.bool,

View file

@ -35,7 +35,7 @@ class SidebarItem extends React.Component {
render() { render() {
let itemClass = classNames({ let itemClass = classNames({
'sidebar__file-item': true, '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--open': this.props.file.isOptionsOpen,
'sidebar__file-item--editing': this.props.file.isEditingName 'sidebar__file-item--editing': this.props.file.isEditingName
}); });
@ -106,7 +106,7 @@ SidebarItem.propTypes = {
file: PropTypes.shape({ file: PropTypes.shape({
id: PropTypes.string.isRequired, id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
isSelected: PropTypes.bool, isSelectedFile: PropTypes.bool,
isOptionsOpen: PropTypes.bool, isOptionsOpen: PropTypes.bool,
isEditingName: PropTypes.bool isEditingName: PropTypes.bool
}).isRequired, }).isRequired,

View file

@ -462,7 +462,7 @@ IDEView.propTypes = {
function mapStateToProps(state) { function mapStateToProps(state) {
return { return {
files: state.files, files: state.files,
selectedFile: state.files.filter(file => file.isSelected)[0], selectedFile: state.files.filter(file => file.isSelectedFile)[0],
htmlFile: getHTMLFile(state.files), htmlFile: getHTMLFile(state.files),
jsFiles: getJSFiles(state.files), jsFiles: getJSFiles(state.files),
cssFiles: getCSSFiles(state.files), cssFiles: getCSSFiles(state.files),

View file

@ -50,7 +50,7 @@ function initialState() {
content: defaultSketch, content: defaultSketch,
id: a, id: a,
_id: a, _id: a,
isSelected: true, isSelectedFile: true,
fileType: 'file', fileType: 'file',
children: [] children: []
}, },
@ -207,9 +207,9 @@ const files = (state, action) => {
case ActionTypes.SET_SELECTED_FILE: case ActionTypes.SET_SELECTED_FILE:
return state.map(file => { return state.map(file => {
if (file.id === action.selectedFile) { 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: case ActionTypes.SHOW_FOLDER_CHILDREN:
return state.map(file => { return state.map(file => {

View file

@ -39,7 +39,7 @@ const fileSchema = new Schema({
url: { type: String }, url: { type: String },
children: { type: [ String ], default: [] }, children: { type: [ String ], default: [] },
fileType: { type: String, default: 'file' }, fileType: { type: String, default: 'file' },
isSelected: { type: Boolean } isSelectedFile: { type: Boolean }
}, { timestamps: true, _id: true }); }, { timestamps: true, _id: true });
fileSchema.virtual('id').get(function(){ fileSchema.virtual('id').get(function(){
@ -71,7 +71,7 @@ projectSchema.set('toJSON', {
// let a = new ObjectId(); // let a = new ObjectId();
// let b = new ObjectId(); // let b = new ObjectId();
// let c = 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: 'index.html', content: defaultHTML, _id: b },
// { name: 'style.css', content: defaultCSS, _id: c }, // { name: 'style.css', content: defaultCSS, _id: c },
// { name: 'root', _id: new ObjectId(), children: [a, b, c] }]; // { name: 'root', _id: new ObjectId(), children: [a, b, c] }];

View file

@ -64,17 +64,32 @@ import Project from '../models/project';
// }); // });
// }); // });
const s3Bucket = `http://p5.js-webeditor.s3.amazonaws.com/`; // const s3Bucket = `http://p5.js-webeditor.s3.amazonaws.com/`;
const s3BucketHttps = `https://s3-us-west-2.amazonaws.com/p5.js-webeditor/`; // 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({}) Project.find({})
.exec((err, projects) => { .exec((err, projects) => {
projects.forEach((project, projectIndex) => { projects.forEach((project, projectIndex) => {
project.files.forEach((file) => { project.files.forEach((file) => {
if (file.url) { if (file.isSelected === true || file.isSelected === false) {
file.url = file.url.replace(s3Bucket, s3BucketHttps); file.isSelectedFile = file.isSelected;
console.log('Updating', file.name); delete file.isSelected;
console.log(file.url);
} }
}); });
project.save((err, savedProject) => { project.save((err, savedProject) => {