diff --git a/client/constants.js b/client/constants.js
index b69e22b2..1a4f1741 100644
--- a/client/constants.js
+++ b/client/constants.js
@@ -23,5 +23,7 @@ export const NEW_PROJECT = 'NEW_PROJECT';
export const SET_PROJECT = 'SET_PROJECT';
export const SET_PROJECTS = 'SET_PROJECTS';
+export const SET_SELECTED_FILE = 'SET_SELECTED_FILE';
+
// eventually, handle errors more specifically and better
export const ERROR = 'ERROR';
diff --git a/client/modules/IDE/actions/project.js b/client/modules/IDE/actions/project.js
index 8d4e1e56..8f820c30 100644
--- a/client/modules/IDE/actions/project.js
+++ b/client/modules/IDE/actions/project.js
@@ -12,7 +12,8 @@ export function getProject(id) {
dispatch({
type: ActionTypes.SET_PROJECT,
project: response.data,
- files: response.data.files
+ files: response.data.files,
+ selectedFile: response.data.selectedFile
});
})
.catch(response => dispatch({
@@ -34,7 +35,7 @@ export function saveProject() {
return (dispatch, getState) => {
const state = getState();
const formParams = Object.assign({}, state.project);
- formParams.files = state.files;
+ formParams.files = [...state.files];
if (state.project.id) {
axios.put(`${ROOT_URL}/projects/${state.project.id}`, formParams, { withCredentials: true })
.then(() => {
@@ -47,6 +48,12 @@ export function saveProject() {
error: response.data
}));
} else {
+ // this might be unnecessary, but to prevent collisions in mongodb
+ formParams.files.map(file => {
+ const newFile = Object.assign({}, file);
+ delete newFile.id;
+ return newFile;
+ });
axios.post(`${ROOT_URL}/projects`, formParams, { withCredentials: true })
.then(response => {
browserHistory.push(`/projects/${response.data.id}`);
@@ -54,6 +61,7 @@ export function saveProject() {
type: ActionTypes.NEW_PROJECT,
name: response.data.name,
id: response.data.id,
+ selectedFile: response.data.selectedFile,
files: response.data.files
});
})
@@ -75,6 +83,7 @@ export function createProject() {
type: ActionTypes.NEW_PROJECT,
name: response.data.name,
id: response.data.id,
+ selectedFile: response.data.selectedFile,
files: response.data.files
});
})
diff --git a/client/modules/IDE/components/Sidebar.js b/client/modules/IDE/components/Sidebar.js
index 3c5d0fe6..4fe0b85b 100644
--- a/client/modules/IDE/components/Sidebar.js
+++ b/client/modules/IDE/components/Sidebar.js
@@ -1,22 +1,32 @@
import React, { PropTypes } from 'react';
+import classNames from 'classnames';
function Sidebar(props) {
return (
- {props.files.map(file =>
- - {file.name}
- )}
+ {props.files.map(file => {
+ let itemClass = classNames({
+ 'sidebar__file-item': true,
+ 'sidebar__file-item--selected': file.id === props.selectedFile.id
+ });
+ return (
+ - {file.name}
+ );
+ })}
);
}
Sidebar.propTypes = {
- files: PropTypes.array.isRequired
+ files: PropTypes.array.isRequired,
+ selectedFile: PropTypes.shape({
+ id: PropTypes.string.isRequired
+ })
};
export default Sidebar;
diff --git a/client/modules/IDE/pages/IDEView.js b/client/modules/IDE/pages/IDEView.js
index 2278a095..6d891791 100644
--- a/client/modules/IDE/pages/IDEView.js
+++ b/client/modules/IDE/pages/IDEView.js
@@ -11,6 +11,7 @@ import * as FileActions from '../actions/files';
import * as IDEActions from '../actions/ide';
import * as PreferencesActions from '../actions/preferences';
import * as ProjectActions from '../actions/project';
+import { getFile } from '../reducers/files';
class IDEView extends React.Component {
componentDidMount() {
@@ -45,14 +46,18 @@ class IDEView extends React.Component {
decreaseFont={this.props.decreaseFont}
fontSize={this.props.preferences.fontSize}
/>
-
+
}
@@ -89,12 +94,17 @@ IDEView.propTypes = {
increaseFont: PropTypes.func.isRequired,
decreaseFont: PropTypes.func.isRequired,
files: PropTypes.array.isRequired,
- updateFileContent: PropTypes.func.isRequired
+ updateFileContent: PropTypes.func.isRequired,
+ selectedFile: PropTypes.shape({
+ id: PropTypes.string,
+ content: PropTypes.string.isRequired
+ })
};
function mapStateToProps(state) {
return {
files: state.files,
+ selectedFile: getFile(state.files, state.ide.selectedFile),
ide: state.ide,
preferences: state.preferences,
user: state.user,
diff --git a/client/modules/IDE/reducers/files.js b/client/modules/IDE/reducers/files.js
index 3a1a03d5..a8bb6991 100644
--- a/client/modules/IDE/reducers/files.js
+++ b/client/modules/IDE/reducers/files.js
@@ -20,14 +20,18 @@ const defaultHTML =