merge master
This commit is contained in:
commit
5cf1249cc7
20 changed files with 729 additions and 248 deletions
|
@ -6,12 +6,13 @@ export const STOP_SKETCH = 'STOP_SKETCH';
|
||||||
|
|
||||||
export const OPEN_PREFERENCES = 'OPEN_PREFERENCES';
|
export const OPEN_PREFERENCES = 'OPEN_PREFERENCES';
|
||||||
export const CLOSE_PREFERENCES = 'CLOSE_PREFERENCES';
|
export const CLOSE_PREFERENCES = 'CLOSE_PREFERENCES';
|
||||||
export const INCREASE_FONTSIZE = 'INCREASE_FONTSIZE';
|
export const SET_FONT_SIZE = 'SET_FONT_SIZE';
|
||||||
export const DECREASE_FONTSIZE = 'DECREASE_FONTSIZE';
|
|
||||||
export const UPDATE_FONTSIZE = 'UPDATE_FONTSIZE';
|
|
||||||
export const INCREASE_INDENTATION = 'INCREASE_INDENTATION';
|
export const INCREASE_INDENTATION = 'INCREASE_INDENTATION';
|
||||||
export const DECREASE_INDENTATION = 'DECREASE_INDENTATION';
|
export const DECREASE_INDENTATION = 'DECREASE_INDENTATION';
|
||||||
export const UPDATE_INDENTATION = 'UPDATE_INDENTATION';
|
export const UPDATE_INDENTATION = 'UPDATE_INDENTATION';
|
||||||
|
export const SET_INDENTATION = 'SET_INDENTATION';
|
||||||
|
|
||||||
export const INDENT_WITH_SPACE = 'INDENT_WITH_SPACE';
|
export const INDENT_WITH_SPACE = 'INDENT_WITH_SPACE';
|
||||||
export const INDENT_WITH_TAB = 'INDENT_WITH_TAB';
|
export const INDENT_WITH_TAB = 'INDENT_WITH_TAB';
|
||||||
|
|
||||||
|
@ -42,7 +43,19 @@ export const CONSOLE_EVENT = 'CONSOLE_EVENT';
|
||||||
export const EXPAND_CONSOLE = 'EXPAND_CONSOLE';
|
export const EXPAND_CONSOLE = 'EXPAND_CONSOLE';
|
||||||
export const COLLAPSE_CONSOLE = 'COLLAPSE_CONSOLE';
|
export const COLLAPSE_CONSOLE = 'COLLAPSE_CONSOLE';
|
||||||
|
|
||||||
|
|
||||||
export const TOGGLE_BEEP = 'TOGGLE_BEEP';
|
export const TOGGLE_BEEP = 'TOGGLE_BEEP';
|
||||||
|
|
||||||
|
export const SHOW_FILE_OPTIONS = 'SHOW_FILE_OPTIONS';
|
||||||
|
export const HIDE_FILE_OPTIONS = 'HIDE_FILE_OPTIONS';
|
||||||
|
|
||||||
|
export const UPDATE_FILE_NAME = 'UPDATE_FILE_NAME';
|
||||||
|
export const DELETE_FILE = 'DELETE_FILE';
|
||||||
|
export const SHOW_EDIT_FILE_NAME = 'SHOW_EDIT_FILE_NAME';
|
||||||
|
export const HIDE_EDIT_FILE_NAME = 'HIDE_EDIT_FILE_NAME';
|
||||||
|
|
||||||
|
export const SET_AUTOSAVE = 'SET_AUTOSAVE';
|
||||||
|
export const SET_PREFERENCES = 'SET_PREFERENCES';
|
||||||
|
|
||||||
// eventually, handle errors more specifically and better
|
// eventually, handle errors more specifically and better
|
||||||
export const ERROR = 'ERROR';
|
export const ERROR = 'ERROR';
|
||||||
|
|
|
@ -112,3 +112,46 @@ export function createFile(formProps) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function showFileOptions(fileId) {
|
||||||
|
return {
|
||||||
|
type: ActionTypes.SHOW_FILE_OPTIONS,
|
||||||
|
id: fileId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hideFileOptions(fileId) {
|
||||||
|
return {
|
||||||
|
type: ActionTypes.HIDE_FILE_OPTIONS,
|
||||||
|
id: fileId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function showEditFileName(id) {
|
||||||
|
return {
|
||||||
|
type: ActionTypes.SHOW_EDIT_FILE_NAME,
|
||||||
|
id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function hideEditFileName(id) {
|
||||||
|
return {
|
||||||
|
type: ActionTypes.HIDE_EDIT_FILE_NAME,
|
||||||
|
id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function updateFileName(id, name) {
|
||||||
|
return {
|
||||||
|
type: ActionTypes.UPDATE_FILE_NAME,
|
||||||
|
id,
|
||||||
|
name
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deleteFile(id) {
|
||||||
|
return {
|
||||||
|
type: ActionTypes.DELETE_FILE,
|
||||||
|
id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -1,53 +1,102 @@
|
||||||
import * as ActionTypes from '../../../constants';
|
import * as ActionTypes from '../../../constants';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
export function increaseFont() {
|
const ROOT_URL = location.href.indexOf('localhost') > 0 ? 'http://localhost:8000/api' : '/api';
|
||||||
return {
|
|
||||||
type: ActionTypes.INCREASE_FONTSIZE
|
function updatePreferences(formParams, dispatch) {
|
||||||
};
|
axios.put(`${ROOT_URL}/preferences`, formParams, { withCredentials: true })
|
||||||
|
.then(() => {
|
||||||
|
})
|
||||||
|
.catch((response) => dispatch({
|
||||||
|
type: ActionTypes.ERROR,
|
||||||
|
error: response.data
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function decreaseFont() {
|
export function setFontSize(value) {
|
||||||
return {
|
return (dispatch, getState) => { // eslint-disable-line
|
||||||
type: ActionTypes.DECREASE_FONTSIZE
|
dispatch({
|
||||||
};
|
type: ActionTypes.SET_FONT_SIZE,
|
||||||
}
|
|
||||||
|
|
||||||
export function updateFont(event) {
|
|
||||||
const value = event.target.value;
|
|
||||||
return {
|
|
||||||
type: ActionTypes.UPDATE_FONTSIZE,
|
|
||||||
value
|
value
|
||||||
|
});
|
||||||
|
const state = getState();
|
||||||
|
if (state.user.authenticated) {
|
||||||
|
const formParams = {
|
||||||
|
preferences: {
|
||||||
|
fontSize: value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
updatePreferences(formParams, dispatch);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function increaseIndentation() {
|
export function setIndentation(value) {
|
||||||
return {
|
return (dispatch, getState) => {
|
||||||
type: ActionTypes.INCREASE_INDENTATION
|
dispatch({
|
||||||
};
|
type: ActionTypes.SET_INDENTATION,
|
||||||
}
|
|
||||||
|
|
||||||
export function decreaseIndentation() {
|
|
||||||
return {
|
|
||||||
type: ActionTypes.DECREASE_INDENTATION
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function updateIndentation(event) {
|
|
||||||
const value = event.target.value;
|
|
||||||
return {
|
|
||||||
type: ActionTypes.UPDATE_INDENTATION,
|
|
||||||
value
|
value
|
||||||
|
});
|
||||||
|
const state = getState();
|
||||||
|
if (state.user.authenticated) {
|
||||||
|
const formParams = {
|
||||||
|
preferences: {
|
||||||
|
indentationAmount: value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
updatePreferences(formParams, dispatch);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function indentWithTab() {
|
export function indentWithTab() {
|
||||||
return {
|
return (dispatch, getState) => {
|
||||||
|
dispatch({
|
||||||
type: ActionTypes.INDENT_WITH_TAB
|
type: ActionTypes.INDENT_WITH_TAB
|
||||||
|
});
|
||||||
|
const state = getState();
|
||||||
|
if (state.user.authenticated) {
|
||||||
|
const formParams = {
|
||||||
|
preferences: {
|
||||||
|
isTabIndent: true
|
||||||
|
}
|
||||||
|
};
|
||||||
|
updatePreferences(formParams, dispatch);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function indentWithSpace() {
|
export function indentWithSpace() {
|
||||||
return {
|
return (dispatch, getState) => {
|
||||||
|
dispatch({
|
||||||
type: ActionTypes.INDENT_WITH_SPACE
|
type: ActionTypes.INDENT_WITH_SPACE
|
||||||
|
});
|
||||||
|
const state = getState();
|
||||||
|
if (state.user.authenticated) {
|
||||||
|
const formParams = {
|
||||||
|
preferences: {
|
||||||
|
isTabIndent: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
updatePreferences(formParams, dispatch);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setAutosave(value) {
|
||||||
|
return (dispatch, getState) => {
|
||||||
|
dispatch({
|
||||||
|
type: ActionTypes.SET_AUTOSAVE,
|
||||||
|
value
|
||||||
|
});
|
||||||
|
const state = getState();
|
||||||
|
if (state.user.authenticated) {
|
||||||
|
const formParams = {
|
||||||
|
preferences: {
|
||||||
|
autosave: value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
updatePreferences(formParams, dispatch);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,53 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import InlineSVG from 'react-inlinesvg';
|
import InlineSVG from 'react-inlinesvg';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { bindActionCreators } from 'redux';
|
// import { bindActionCreators } from 'redux';
|
||||||
import { connect } from 'react-redux';
|
// import { connect } from 'react-redux';
|
||||||
import * as PreferencesActions from '../actions/preferences';
|
// import * as PreferencesActions from '../actions/preferences';
|
||||||
|
|
||||||
const exitUrl = require('../../../images/exit.svg');
|
const exitUrl = require('../../../images/exit.svg');
|
||||||
const plusUrl = require('../../../images/plus.svg');
|
const plusUrl = require('../../../images/plus.svg');
|
||||||
const minusUrl = require('../../../images/minus.svg');
|
const minusUrl = require('../../../images/minus.svg');
|
||||||
|
|
||||||
function Preferences(props) {
|
class Preferences extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.handleUpdateAutosave = this.handleUpdateAutosave.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUpdateFont(event) {
|
||||||
|
this.props.setFontSize(parseInt(event.target.value, 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUpdateIndentation(event) {
|
||||||
|
this.props.setIndentation(parseInt(event.target.value, 10));
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUpdateAutosave(event) {
|
||||||
|
const value = event.target.value === 'true';
|
||||||
|
this.props.setAutosave(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
const preferencesContainerClass = classNames({
|
const preferencesContainerClass = classNames({
|
||||||
preferences: true,
|
preferences: true,
|
||||||
'preferences--selected': props.isVisible
|
'preferences--selected': this.props.isVisible
|
||||||
});
|
});
|
||||||
let preferencesTabOptionClass = classNames({
|
let preferencesTabOptionClass = classNames({
|
||||||
preference__option: true,
|
preference__option: true,
|
||||||
'preference__option--selected': props.isTabIndent
|
'preference__option--selected': this.props.isTabIndent
|
||||||
});
|
});
|
||||||
let preferencesSpaceOptionClass = classNames({
|
let preferencesSpaceOptionClass = classNames({
|
||||||
preference__option: true,
|
preference__option: true,
|
||||||
'preference__option--selected': !props.isTabIndent
|
'preference__option--selected': !this.props.isTabIndent
|
||||||
|
});
|
||||||
|
let autosaveOnClass = classNames({
|
||||||
|
preference__option: true,
|
||||||
|
'preference__option--selected': this.props.autosave
|
||||||
|
});
|
||||||
|
let autosaveOffClass = classNames({
|
||||||
|
preference__option: true,
|
||||||
|
'preference__option--selected': !this.props.autosave
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<section className={preferencesContainerClass} tabIndex="0" title="preference-menu">
|
<section className={preferencesContainerClass} tabIndex="0" title="preference-menu">
|
||||||
|
@ -28,7 +55,7 @@ function Preferences(props) {
|
||||||
<h2 className="preferences__title">Preferences</h2>
|
<h2 className="preferences__title">Preferences</h2>
|
||||||
<button
|
<button
|
||||||
className="preferences__exit-button"
|
className="preferences__exit-button"
|
||||||
onClick={props.closePreferences}
|
onClick={this.props.closePreferences}
|
||||||
title="exit"
|
title="exit"
|
||||||
aria-label="exit preferences"
|
aria-label="exit preferences"
|
||||||
>
|
>
|
||||||
|
@ -39,8 +66,8 @@ function Preferences(props) {
|
||||||
<div className="preference">
|
<div className="preference">
|
||||||
<h4 className="preference__title">Text Size</h4>
|
<h4 className="preference__title">Text Size</h4>
|
||||||
<button
|
<button
|
||||||
className="preference__plus-button"
|
className="preference__minus-button"
|
||||||
onClick={props.decreaseFont}
|
onClick={() => this.props.setFontSize(this.props.fontSize - 2)}
|
||||||
aria-label="decrease font size"
|
aria-label="decrease font size"
|
||||||
>
|
>
|
||||||
<InlineSVG src={minusUrl} alt="Decrease Font Size" />
|
<InlineSVG src={minusUrl} alt="Decrease Font Size" />
|
||||||
|
@ -51,13 +78,13 @@ function Preferences(props) {
|
||||||
aria-live="status"
|
aria-live="status"
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
role="status"
|
role="status"
|
||||||
value={props.fontSize}
|
value={this.props.fontSize}
|
||||||
onChange={props.updateFont}
|
onChange={this.handleUpdateFont}
|
||||||
>
|
>
|
||||||
</input>
|
</input>
|
||||||
<button
|
<button
|
||||||
className="preference__minus-button"
|
className="preference__plus-button"
|
||||||
onClick={props.increaseFont}
|
onClick={() => this.props.setFontSize(this.props.fontSize + 2)}
|
||||||
aria-label="increase font size"
|
aria-label="increase font size"
|
||||||
>
|
>
|
||||||
<InlineSVG src={plusUrl} alt="Increase Font Size" />
|
<InlineSVG src={plusUrl} alt="Increase Font Size" />
|
||||||
|
@ -68,8 +95,8 @@ function Preferences(props) {
|
||||||
<div className="preference">
|
<div className="preference">
|
||||||
<h4 className="preference__title">Indentation Amount</h4>
|
<h4 className="preference__title">Indentation Amount</h4>
|
||||||
<button
|
<button
|
||||||
className="preference__plus-button"
|
className="preference__minus-button"
|
||||||
onClick={props.decreaseIndentation}
|
onClick={() => this.props.setIndentation(this.props.indentationAmount - 2)}
|
||||||
aria-label="decrease indentation amount"
|
aria-label="decrease indentation amount"
|
||||||
>
|
>
|
||||||
<InlineSVG src={minusUrl} alt="DecreaseIndentation Amount" />
|
<InlineSVG src={minusUrl} alt="DecreaseIndentation Amount" />
|
||||||
|
@ -80,51 +107,55 @@ function Preferences(props) {
|
||||||
aria-live="status"
|
aria-live="status"
|
||||||
aria-live="polite"
|
aria-live="polite"
|
||||||
role="status"
|
role="status"
|
||||||
value={props.indentationAmount}
|
value={this.props.indentationAmount}
|
||||||
onChange={props.updateIndentation}
|
onChange={this.handleUpdateIndentation}
|
||||||
>
|
>
|
||||||
</input>
|
</input>
|
||||||
<button
|
<button
|
||||||
className="preference__minus-button"
|
className="preference__plus-button"
|
||||||
onClick={props.increaseIndentation}
|
onClick={() => this.props.setIndentation(this.props.indentationAmount + 2)}
|
||||||
aria-label="increase indentation amount"
|
aria-label="increase indentation amount"
|
||||||
>
|
>
|
||||||
<InlineSVG src={plusUrl} alt="IncreaseIndentation Amount" />
|
<InlineSVG src={plusUrl} alt="IncreaseIndentation Amount" />
|
||||||
<h6 className="preference__label">Increase</h6>
|
<h6 className="preference__label">Increase</h6>
|
||||||
</button>
|
</button>
|
||||||
<div className="preference__vertical-list">
|
<div className="preference__vertical-list">
|
||||||
<button className={preferencesSpaceOptionClass} onClick={props.indentWithSpace} aria-label="indentation with space">Spaces</button>
|
<button className={preferencesSpaceOptionClass} onClick={this.props.indentWithSpace} aria-label="indentation with space">Spaces</button>
|
||||||
<button className={preferencesTabOptionClass} onClick={props.indentWithTab} aria-label="indentation with tab">Tabs</button>
|
<button className={preferencesTabOptionClass} onClick={this.props.indentWithTab} aria-label="indentation with tab">Tabs</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="preference">
|
||||||
|
<h4 className="preference__title">Autosave</h4>
|
||||||
|
<div className="preference__options">
|
||||||
|
<button
|
||||||
|
className={autosaveOnClass}
|
||||||
|
onClick={() => this.props.setAutosave(true)}
|
||||||
|
aria-label="autosave on"
|
||||||
|
>On</button>
|
||||||
|
<button
|
||||||
|
className={autosaveOffClass}
|
||||||
|
onClick={() => this.props.setAutosave(false)}
|
||||||
|
aria-label="autosave off"
|
||||||
|
>Off</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
|
||||||
return {
|
|
||||||
...state.preferences
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function mapDispatchToProps(dispatch) {
|
|
||||||
return bindActionCreators(PreferencesActions, dispatch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Preferences.propTypes = {
|
Preferences.propTypes = {
|
||||||
isVisible: PropTypes.bool.isRequired,
|
isVisible: PropTypes.bool.isRequired,
|
||||||
closePreferences: PropTypes.func.isRequired,
|
closePreferences: PropTypes.func.isRequired,
|
||||||
decreaseFont: PropTypes.func.isRequired,
|
|
||||||
updateFont: PropTypes.func.isRequired,
|
|
||||||
fontSize: PropTypes.number.isRequired,
|
fontSize: PropTypes.number.isRequired,
|
||||||
increaseFont: PropTypes.func.isRequired,
|
|
||||||
indentationAmount: PropTypes.number.isRequired,
|
indentationAmount: PropTypes.number.isRequired,
|
||||||
decreaseIndentation: PropTypes.func.isRequired,
|
setIndentation: PropTypes.func.isRequired,
|
||||||
increaseIndentation: PropTypes.func.isRequired,
|
|
||||||
updateIndentation: PropTypes.func.isRequired,
|
|
||||||
indentWithSpace: PropTypes.func.isRequired,
|
indentWithSpace: PropTypes.func.isRequired,
|
||||||
indentWithTab: PropTypes.func.isRequired,
|
indentWithTab: PropTypes.func.isRequired,
|
||||||
isTabIndent: PropTypes.bool.isRequired
|
isTabIndent: PropTypes.bool.isRequired,
|
||||||
|
setFontSize: PropTypes.func.isRequired,
|
||||||
|
autosave: PropTypes.bool.isRequired,
|
||||||
|
setAutosave: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(Preferences);
|
export default Preferences;
|
||||||
|
|
|
@ -1,13 +1,24 @@
|
||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import InlineSVG from 'react-inlinesvg';
|
import InlineSVG from 'react-inlinesvg';
|
||||||
|
import SidebarItem from './SidebarItem';
|
||||||
const rightArrowUrl = require('../../../images/right-arrow.svg');
|
const rightArrowUrl = require('../../../images/right-arrow.svg');
|
||||||
const leftArrowUrl = require('../../../images/left-arrow.svg');
|
const leftArrowUrl = require('../../../images/left-arrow.svg');
|
||||||
|
|
||||||
function Sidebar(props) {
|
class Sidebar extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.resetSelectedFile = this.resetSelectedFile.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
resetSelectedFile() {
|
||||||
|
this.props.setSelectedFile(this.props.files[0].id);
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
const sidebarClass = classNames({
|
const sidebarClass = classNames({
|
||||||
sidebar: true,
|
sidebar: true,
|
||||||
'sidebar--contracted': !props.isExpanded
|
'sidebar--contracted': !this.props.isExpanded
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -18,54 +29,61 @@ function Sidebar(props) {
|
||||||
<button
|
<button
|
||||||
aria-label="add file"
|
aria-label="add file"
|
||||||
className="sidebar__add"
|
className="sidebar__add"
|
||||||
onClick={props.newFile}
|
onClick={this.props.newFile}
|
||||||
>
|
>
|
||||||
+
|
+
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
aria-label="collapse file navigation"
|
aria-label="collapse file navigation"
|
||||||
className="sidebar__contract"
|
className="sidebar__contract"
|
||||||
onClick={props.collapseSidebar}
|
onClick={this.props.collapseSidebar}
|
||||||
>
|
>
|
||||||
<InlineSVG src={leftArrowUrl} />
|
<InlineSVG src={leftArrowUrl} />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
aria-label="expand file navigation"
|
aria-label="expand file navigation"
|
||||||
className="sidebar__expand"
|
className="sidebar__expand"
|
||||||
onClick={props.expandSidebar}
|
onClick={this.props.expandSidebar}
|
||||||
>
|
>
|
||||||
<InlineSVG src={rightArrowUrl} />
|
<InlineSVG src={rightArrowUrl} />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul className="sidebar__file-list">
|
<ul className="sidebar__file-list">
|
||||||
{props.files.map(file => {
|
{this.props.files.map((file, fileIndex) =>
|
||||||
let itemClass = classNames({
|
<SidebarItem
|
||||||
'sidebar__file-item': true,
|
|
||||||
'sidebar__file-item--selected': file.id === props.selectedFile.id
|
|
||||||
});
|
|
||||||
return (
|
|
||||||
<li
|
|
||||||
className={itemClass}
|
|
||||||
key={file.id}
|
key={file.id}
|
||||||
>
|
file={file}
|
||||||
<a
|
setSelectedFile={this.props.setSelectedFile}
|
||||||
onClick={() => props.setSelectedFile(file.id)}
|
fileIndex={fileIndex}
|
||||||
>{file.name}</a>
|
showFileOptions={this.props.showFileOptions}
|
||||||
</li>
|
hideFileOptions={this.props.hideFileOptions}
|
||||||
);
|
deleteFile={this.props.deleteFile}
|
||||||
})}
|
resetSelectedFile={this.resetSelectedFile}
|
||||||
|
showEditFileName={this.props.showEditFileName}
|
||||||
|
hideEditFileName={this.props.hideEditFileName}
|
||||||
|
updateFileName={this.props.updateFileName}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sidebar.propTypes = {
|
Sidebar.propTypes = {
|
||||||
files: PropTypes.array.isRequired,
|
files: PropTypes.array.isRequired,
|
||||||
selectedFile: PropTypes.shape({
|
setSelectedFile: PropTypes.func.isRequired,
|
||||||
id: PropTypes.string.isRequired
|
isExpanded: PropTypes.bool.isRequired,
|
||||||
}),
|
newFile: PropTypes.func.isRequired,
|
||||||
setSelectedFile: PropTypes.func.isRequired
|
collapseSidebar: PropTypes.func.isRequired,
|
||||||
|
expandSidebar: PropTypes.func.isRequired,
|
||||||
|
showFileOptions: PropTypes.func.isRequired,
|
||||||
|
hideFileOptions: PropTypes.func.isRequired,
|
||||||
|
deleteFile: PropTypes.func.isRequired,
|
||||||
|
showEditFileName: PropTypes.func.isRequired,
|
||||||
|
hideEditFileName: PropTypes.func.isRequired,
|
||||||
|
updateFileName: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Sidebar;
|
export default Sidebar;
|
||||||
|
|
118
client/modules/IDE/components/SidebarItem.js
Normal file
118
client/modules/IDE/components/SidebarItem.js
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
import React, { PropTypes } from 'react';
|
||||||
|
import InlineSVG from 'react-inlinesvg';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
const downArrowUrl = require('../../../images/down-arrow.svg');
|
||||||
|
|
||||||
|
class SidebarItem extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.handleKeyPress = this.handleKeyPress.bind(this);
|
||||||
|
this.handleFileNameChange = this.handleFileNameChange.bind(this);
|
||||||
|
this.validateFileName = this.validateFileName.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleFileNameChange(event) {
|
||||||
|
this.props.updateFileName(this.props.file.id, event.target.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleKeyPress(event) {
|
||||||
|
console.log(event.key);
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
this.props.hideEditFileName(this.props.file.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
validateFileName() {
|
||||||
|
if (!this.props.file.name.match(/.*\.(js|css|html|json)$/)) {
|
||||||
|
this.props.updateFileName(this.props.file.id, this.originalFileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
let itemClass = classNames({
|
||||||
|
'sidebar__file-item': true,
|
||||||
|
'sidebar__file-item--selected': this.props.file.isSelected,
|
||||||
|
'sidebar__file-item--open': this.props.file.isOptionsOpen,
|
||||||
|
'sidebar__file-item--editing': this.props.file.isEditingName
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li
|
||||||
|
className={itemClass}
|
||||||
|
onBlur={() => this.props.hideFileOptions(this.props.file.id)}
|
||||||
|
tabIndex={this.props.fileIndex}
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
className="sidebar__file-item-name"
|
||||||
|
onClick={() => this.props.setSelectedFile(this.props.file.id)}
|
||||||
|
>{this.props.file.name}</a>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
className="sidebar__file-item-input"
|
||||||
|
value={this.props.file.name}
|
||||||
|
onChange={this.handleFileNameChange}
|
||||||
|
ref="fileNameInput"
|
||||||
|
onBlur={() => {
|
||||||
|
this.validateFileName();
|
||||||
|
this.props.hideEditFileName(this.props.file.id);
|
||||||
|
}}
|
||||||
|
onKeyPress={this.handleKeyPress}
|
||||||
|
/>
|
||||||
|
<a
|
||||||
|
className="sidebar__file-item-show-options"
|
||||||
|
onClick={() => this.props.showFileOptions(this.props.file.id)}
|
||||||
|
>
|
||||||
|
<InlineSVG src={downArrowUrl} />
|
||||||
|
</a>
|
||||||
|
<div ref="fileOptions" className="sidebar__file-item-options">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a
|
||||||
|
onClick={() => {
|
||||||
|
this.originalFileName = this.props.file.name;
|
||||||
|
this.props.showEditFileName(this.props.file.id);
|
||||||
|
setTimeout(() => this.refs.fileNameInput.focus(), 0);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Rename
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a
|
||||||
|
onClick={() => {
|
||||||
|
if (window.confirm(`Are you sure you want to delete ${this.props.file.name}?`)) {
|
||||||
|
this.props.deleteFile(this.props.file.id);
|
||||||
|
this.props.resetSelectedFile();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SidebarItem.propTypes = {
|
||||||
|
file: PropTypes.shape({
|
||||||
|
id: PropTypes.string.isRequired,
|
||||||
|
name: PropTypes.string.isRequired,
|
||||||
|
isSelected: PropTypes.bool,
|
||||||
|
isOptionsOpen: PropTypes.bool,
|
||||||
|
isEditingName: PropTypes.bool
|
||||||
|
}).isRequired,
|
||||||
|
setSelectedFile: PropTypes.func.isRequired,
|
||||||
|
fileIndex: PropTypes.number.isRequired,
|
||||||
|
showFileOptions: PropTypes.func.isRequired,
|
||||||
|
hideFileOptions: PropTypes.func.isRequired,
|
||||||
|
deleteFile: PropTypes.func.isRequired,
|
||||||
|
resetSelectedFile: PropTypes.func.isRequired,
|
||||||
|
showEditFileName: PropTypes.func.isRequired,
|
||||||
|
hideEditFileName: PropTypes.func.isRequired,
|
||||||
|
updateFileName: PropTypes.func.isRequired
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SidebarItem;
|
|
@ -13,15 +13,45 @@ import * as FileActions from '../actions/files';
|
||||||
import * as IDEActions from '../actions/ide';
|
import * as IDEActions from '../actions/ide';
|
||||||
import * as ProjectActions from '../actions/project';
|
import * as ProjectActions from '../actions/project';
|
||||||
import * as EditorHiddenActions from '../actions/editorHidden';
|
import * as EditorHiddenActions from '../actions/editorHidden';
|
||||||
import { getFile, getHTMLFile, getJSFiles, getCSSFiles } from '../reducers/files';
|
import * as PreferencesActions from '../actions/preferences';
|
||||||
|
import { getFile, getHTMLFile, getJSFiles, getCSSFiles, setSelectedFile } from '../reducers/files';
|
||||||
|
|
||||||
class IDEView extends React.Component {
|
class IDEView extends React.Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
if (this.props.params.project_id) {
|
if (this.props.params.project_id) {
|
||||||
const id = this.props.params.project_id;
|
const id = this.props.params.project_id;
|
||||||
this.props.getProject(id);
|
this.props.getProject(id);
|
||||||
|
|
||||||
|
// if autosave is on and the user is the owner of the project
|
||||||
|
if (this.props.preferences.autosave
|
||||||
|
&& this.props.project.owner
|
||||||
|
&& this.props.project.owner.id === this.props.user.id) {
|
||||||
|
this.autosaveInterval = setInterval(this.props.saveProject, 30000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(prevProps) {
|
||||||
|
// if user is the owner of the project
|
||||||
|
if (this.props.project.owner && this.props.project.owner.id === this.props.user.id) {
|
||||||
|
// if the user turns on autosave
|
||||||
|
// or the user saves the project for the first time
|
||||||
|
if (!this.autosaveInterval &&
|
||||||
|
((this.props.preferences.autosave && !prevProps.preferences.autosave) ||
|
||||||
|
(this.props.project.id && !prevProps.project.id))) {
|
||||||
|
this.autosaveInterval = setInterval(this.props.saveProject, 30000);
|
||||||
|
// if user turns off autosave preference
|
||||||
|
} else if (this.autosaveInterval && !this.props.preferences.autosave && prevProps.preferences.autosave) {
|
||||||
|
clearInterval(this.autosaveInterval);
|
||||||
|
this.autosaveInterval = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
clearInterval(this.autosaveInterval);
|
||||||
|
this.autosaveInterval = null;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
|
@ -47,16 +77,30 @@ class IDEView extends React.Component {
|
||||||
<Preferences
|
<Preferences
|
||||||
isVisible={this.props.ide.preferencesIsVisible}
|
isVisible={this.props.ide.preferencesIsVisible}
|
||||||
closePreferences={this.props.closePreferences}
|
closePreferences={this.props.closePreferences}
|
||||||
|
fontSize={this.props.preferences.fontSize}
|
||||||
|
indentationAmount={this.props.preferences.indentationAmount}
|
||||||
|
setIndentation={this.props.setIndentation}
|
||||||
|
indentWithSpace={this.props.indentWithSpace}
|
||||||
|
indentWithTab={this.props.indentWithTab}
|
||||||
|
isTabIndent={this.props.preferences.isTabIndent}
|
||||||
|
setFontSize={this.props.setFontSize}
|
||||||
|
autosave={this.props.preferences.autosave}
|
||||||
|
setAutosave={this.props.setAutosave}
|
||||||
/>
|
/>
|
||||||
<div className="editor-preview-container">
|
<div className="editor-preview-container">
|
||||||
<Sidebar
|
<Sidebar
|
||||||
files={this.props.files}
|
files={this.props.files}
|
||||||
selectedFile={this.props.selectedFile}
|
|
||||||
setSelectedFile={this.props.setSelectedFile}
|
setSelectedFile={this.props.setSelectedFile}
|
||||||
newFile={this.props.newFile}
|
newFile={this.props.newFile}
|
||||||
isExpanded={this.props.ide.sidebarIsExpanded}
|
isExpanded={this.props.ide.sidebarIsExpanded}
|
||||||
expandSidebar={this.props.expandSidebar}
|
expandSidebar={this.props.expandSidebar}
|
||||||
collapseSidebar={this.props.collapseSidebar}
|
collapseSidebar={this.props.collapseSidebar}
|
||||||
|
showFileOptions={this.props.showFileOptions}
|
||||||
|
hideFileOptions={this.props.hideFileOptions}
|
||||||
|
deleteFile={this.props.deleteFile}
|
||||||
|
showEditFileName={this.props.showEditFileName}
|
||||||
|
hideEditFileName={this.props.hideEditFileName}
|
||||||
|
updateFileName={this.props.updateFileName}
|
||||||
/>
|
/>
|
||||||
<div className="editor-console-container">
|
<div className="editor-console-container">
|
||||||
<div className="editor-linenumber" aria-live="assertive" id="editor-linenumber"></div>
|
<div className="editor-linenumber" aria-live="assertive" id="editor-linenumber"></div>
|
||||||
|
@ -115,7 +159,8 @@ IDEView.propTypes = {
|
||||||
}),
|
}),
|
||||||
getProject: PropTypes.func.isRequired,
|
getProject: PropTypes.func.isRequired,
|
||||||
user: PropTypes.shape({
|
user: PropTypes.shape({
|
||||||
authenticated: PropTypes.bool.isRequired
|
authenticated: PropTypes.bool.isRequired,
|
||||||
|
id: PropTypes.string
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
createProject: PropTypes.func.isRequired,
|
createProject: PropTypes.func.isRequired,
|
||||||
saveProject: PropTypes.func.isRequired,
|
saveProject: PropTypes.func.isRequired,
|
||||||
|
@ -130,9 +175,11 @@ IDEView.propTypes = {
|
||||||
startSketch: PropTypes.func.isRequired,
|
startSketch: PropTypes.func.isRequired,
|
||||||
stopSketch: PropTypes.func.isRequired,
|
stopSketch: PropTypes.func.isRequired,
|
||||||
project: PropTypes.shape({
|
project: PropTypes.shape({
|
||||||
|
id: PropTypes.string,
|
||||||
name: PropTypes.string.isRequired,
|
name: PropTypes.string.isRequired,
|
||||||
owner: PropTypes.shape({
|
owner: PropTypes.shape({
|
||||||
username: PropTypes.string
|
username: PropTypes.string,
|
||||||
|
id: PropTypes.string
|
||||||
})
|
})
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
setProjectName: PropTypes.func.isRequired,
|
setProjectName: PropTypes.func.isRequired,
|
||||||
|
@ -144,9 +191,15 @@ IDEView.propTypes = {
|
||||||
preferences: PropTypes.shape({
|
preferences: PropTypes.shape({
|
||||||
fontSize: PropTypes.number.isRequired,
|
fontSize: PropTypes.number.isRequired,
|
||||||
indentationAmount: PropTypes.number.isRequired,
|
indentationAmount: PropTypes.number.isRequired,
|
||||||
isTabIndent: PropTypes.bool.isRequired
|
isTabIndent: PropTypes.bool.isRequired,
|
||||||
|
autosave: PropTypes.bool.isRequired
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
closePreferences: PropTypes.func.isRequired,
|
closePreferences: PropTypes.func.isRequired,
|
||||||
|
setFontSize: PropTypes.func.isRequired,
|
||||||
|
setIndentation: PropTypes.func.isRequired,
|
||||||
|
indentWithTab: PropTypes.func.isRequired,
|
||||||
|
indentWithSpace: PropTypes.func.isRequired,
|
||||||
|
setAutosave: PropTypes.func.isRequired,
|
||||||
files: PropTypes.array.isRequired,
|
files: PropTypes.array.isRequired,
|
||||||
updateFileContent: PropTypes.func.isRequired,
|
updateFileContent: PropTypes.func.isRequired,
|
||||||
selectedFile: PropTypes.shape({
|
selectedFile: PropTypes.shape({
|
||||||
|
@ -166,11 +219,17 @@ IDEView.propTypes = {
|
||||||
cloneProject: PropTypes.func.isRequired,
|
cloneProject: PropTypes.func.isRequired,
|
||||||
expandConsole: PropTypes.func.isRequired,
|
expandConsole: PropTypes.func.isRequired,
|
||||||
collapseConsole: PropTypes.func.isRequired,
|
collapseConsole: PropTypes.func.isRequired,
|
||||||
|
showFileOptions: PropTypes.func.isRequired,
|
||||||
|
hideFileOptions: PropTypes.func.isRequired,
|
||||||
|
deleteFile: PropTypes.func.isRequired,
|
||||||
|
showEditFileName: PropTypes.func.isRequired,
|
||||||
|
hideEditFileName: PropTypes.func.isRequired,
|
||||||
|
updateFileName: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
return {
|
return {
|
||||||
files: state.files,
|
files: setSelectedFile(state.files, state.ide.selectedFile),
|
||||||
selectedFile: getFile(state.files, state.ide.selectedFile),
|
selectedFile: getFile(state.files, state.ide.selectedFile),
|
||||||
htmlFile: getHTMLFile(state.files),
|
htmlFile: getHTMLFile(state.files),
|
||||||
jsFiles: getJSFiles(state.files),
|
jsFiles: getJSFiles(state.files),
|
||||||
|
@ -188,7 +247,8 @@ function mapDispatchToProps(dispatch) {
|
||||||
EditorHiddenActions,
|
EditorHiddenActions,
|
||||||
FileActions,
|
FileActions,
|
||||||
ProjectActions,
|
ProjectActions,
|
||||||
IDEActions),
|
IDEActions,
|
||||||
|
PreferencesActions),
|
||||||
dispatch);
|
dispatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,11 +73,61 @@ const files = (state = initialState, action) => {
|
||||||
return [...action.files];
|
return [...action.files];
|
||||||
case ActionTypes.CREATE_FILE:
|
case ActionTypes.CREATE_FILE:
|
||||||
return [...state, { name: action.name, id: action.id, content: '', url: action.url }];
|
return [...state, { name: action.name, id: action.id, content: '', url: action.url }];
|
||||||
|
case ActionTypes.SHOW_FILE_OPTIONS:
|
||||||
|
return state.map(file => {
|
||||||
|
if (file.id !== action.id) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.assign({}, file, { isOptionsOpen: true });
|
||||||
|
});
|
||||||
|
case ActionTypes.HIDE_FILE_OPTIONS:
|
||||||
|
return state.map(file => {
|
||||||
|
if (file.id !== action.id) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.assign({}, file, { isOptionsOpen: false });
|
||||||
|
});
|
||||||
|
case ActionTypes.UPDATE_FILE_NAME:
|
||||||
|
return state.map(file => {
|
||||||
|
if (file.id !== action.id) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.assign({}, file, { name: action.name });
|
||||||
|
});
|
||||||
|
case ActionTypes.DELETE_FILE:
|
||||||
|
return state.filter(file => file.id !== action.id);
|
||||||
|
case ActionTypes.SHOW_EDIT_FILE_NAME:
|
||||||
|
return state.map(file => {
|
||||||
|
if (file.id !== action.id) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.assign({}, file, { isEditingName: true });
|
||||||
|
});
|
||||||
|
case ActionTypes.HIDE_EDIT_FILE_NAME:
|
||||||
|
return state.map(file => {
|
||||||
|
if (file.id !== action.id) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.assign({}, file, { isEditingName: false });
|
||||||
|
});
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const setSelectedFile = (state, id) =>
|
||||||
|
state.map(file => {
|
||||||
|
if (file.id === id) {
|
||||||
|
return Object.assign({}, file, { isSelected: true });
|
||||||
|
}
|
||||||
|
return file;
|
||||||
|
});
|
||||||
|
|
||||||
export const getFile = (state, id) => state.filter(file => file.id === id)[0];
|
export const getFile = (state, id) => state.filter(file => file.id === id)[0];
|
||||||
export const getHTMLFile = (state) => state.filter(file => file.name.match(/.*\.html$/))[0];
|
export const getHTMLFile = (state) => state.filter(file => file.name.match(/.*\.html$/))[0];
|
||||||
export const getJSFiles = (state) => state.filter(file => file.name.match(/.*\.js$/));
|
export const getJSFiles = (state) => state.filter(file => file.name.match(/.*\.js$/));
|
||||||
|
|
|
@ -3,35 +3,16 @@ import * as ActionTypes from '../../../constants';
|
||||||
const initialState = {
|
const initialState = {
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
indentationAmount: 2,
|
indentationAmount: 2,
|
||||||
isTabIndent: true
|
isTabIndent: true,
|
||||||
|
autosave: true
|
||||||
};
|
};
|
||||||
|
|
||||||
const preferences = (state = initialState, action) => {
|
const preferences = (state = initialState, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionTypes.INCREASE_FONTSIZE:
|
case ActionTypes.SET_FONT_SIZE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, { fontSize: action.value });
|
||||||
fontSize: state.fontSize + 2
|
case ActionTypes.SET_INDENTATION:
|
||||||
});
|
return Object.assign({}, state, { indentationAmount: action.value });
|
||||||
case ActionTypes.DECREASE_FONTSIZE:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
fontSize: state.fontSize - 2
|
|
||||||
});
|
|
||||||
case ActionTypes.UPDATE_FONTSIZE:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
fontSize: parseInt(action.value, 10)
|
|
||||||
});
|
|
||||||
case ActionTypes.INCREASE_INDENTATION:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
indentationAmount: state.indentationAmount + 2
|
|
||||||
});
|
|
||||||
case ActionTypes.DECREASE_INDENTATION:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
indentationAmount: state.indentationAmount - 2
|
|
||||||
});
|
|
||||||
case ActionTypes.UPDATE_INDENTATION:
|
|
||||||
return Object.assign({}, state, {
|
|
||||||
indentationAmount: parseInt(action.value, 10)
|
|
||||||
});
|
|
||||||
case ActionTypes.INDENT_WITH_TAB:
|
case ActionTypes.INDENT_WITH_TAB:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
isTabIndent: true
|
isTabIndent: true
|
||||||
|
@ -40,6 +21,10 @@ const preferences = (state = initialState, action) => {
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
isTabIndent: false
|
isTabIndent: false
|
||||||
});
|
});
|
||||||
|
case ActionTypes.SET_AUTOSAVE:
|
||||||
|
return Object.assign({}, state, { autosave: action.value });
|
||||||
|
case ActionTypes.SET_PREFERENCES:
|
||||||
|
return action.preferences;
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,16 +19,20 @@ class SketchListView extends React.Component {
|
||||||
user={this.props.user}
|
user={this.props.user}
|
||||||
createProject={this.props.createProject}
|
createProject={this.props.createProject}
|
||||||
saveProject={this.props.saveProject}
|
saveProject={this.props.saveProject}
|
||||||
|
exportProjectAsZip={this.props.exportProjectAsZip}
|
||||||
|
cloneProject={this.props.cloneProject}
|
||||||
/>
|
/>
|
||||||
<table className="sketches-table" summary="table containing all saved projects">
|
<table className="sketches-table" summary="table containing all saved projects">
|
||||||
<thead>
|
<thead>
|
||||||
|
<tr>
|
||||||
<th scope="col">Name</th>
|
<th scope="col">Name</th>
|
||||||
<th scope="col">Created</th>
|
<th scope="col">Created</th>
|
||||||
<th scope="col">Last Updated</th>
|
<th scope="col">Last Updated</th>
|
||||||
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{this.props.sketches.map(sketch =>
|
{this.props.sketches.map(sketch =>
|
||||||
<tr className="sketches-table__row">
|
<tr className="sketches-table__row" key={sketch.id}>
|
||||||
<td scope="row"><Link to={`/projects/${sketch._id}`}>{sketch.name}</Link></td>
|
<td scope="row"><Link to={`/projects/${sketch._id}`}>{sketch.name}</Link></td>
|
||||||
<td>{moment(sketch.createdAt).format('MMM D, YYYY')}</td>
|
<td>{moment(sketch.createdAt).format('MMM D, YYYY')}</td>
|
||||||
<td>{moment(sketch.updatedAt).format('MMM D, YYYY')}</td>
|
<td>{moment(sketch.updatedAt).format('MMM D, YYYY')}</td>
|
||||||
|
@ -46,7 +50,9 @@ SketchListView.propTypes = {
|
||||||
createProject: PropTypes.func.isRequired,
|
createProject: PropTypes.func.isRequired,
|
||||||
saveProject: PropTypes.func.isRequired,
|
saveProject: PropTypes.func.isRequired,
|
||||||
getProjects: PropTypes.func.isRequired,
|
getProjects: PropTypes.func.isRequired,
|
||||||
sketches: PropTypes.array.isRequired
|
sketches: PropTypes.array.isRequired,
|
||||||
|
exportProjectAsZip: PropTypes.func.isRequired,
|
||||||
|
cloneProject: PropTypes.func.isRequired
|
||||||
};
|
};
|
||||||
|
|
||||||
function mapStateToProps(state) {
|
function mapStateToProps(state) {
|
||||||
|
|
|
@ -46,7 +46,13 @@ export function getUser() {
|
||||||
type: ActionTypes.AUTH_USER,
|
type: ActionTypes.AUTH_USER,
|
||||||
user: response.data
|
user: response.data
|
||||||
});
|
});
|
||||||
|
dispatch({
|
||||||
|
type: ActionTypes.SET_PREFERENCES,
|
||||||
|
preferences: response.data.preferences
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(response => dispatch(authError(response.data.error)));
|
.catch(response => {
|
||||||
|
dispatch(authError(response.data.error));
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@
|
||||||
%preference-option {
|
%preference-option {
|
||||||
background-color: $light-button-background-color;
|
background-color: $light-button-background-color;
|
||||||
color: $light-inactive-text-color;
|
color: $light-inactive-text-color;
|
||||||
font-size: #{14 / $base-font-size}rem;
|
font-size: #{12 / $base-font-size}rem;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
margin-bottom: #{5 / $base-font-size}rem;
|
margin-bottom: #{5 / $base-font-size}rem;
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
margin: 0;
|
margin: 0;
|
||||||
line-height: #{20 / $base-font-size}rem;
|
line-height: #{20 / $base-font-size}rem;
|
||||||
color: $light-inactive-text-color;
|
color: $light-inactive-text-color;
|
||||||
|
font-size: #{9 / $base-font-size}rem;
|
||||||
&:hover {
|
&:hover {
|
||||||
color: $light-inactive-text-color;
|
color: $light-inactive-text-color;
|
||||||
}
|
}
|
||||||
|
@ -69,13 +70,22 @@
|
||||||
.preference__vertical-list {
|
.preference__vertical-list {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
width: #{90 / $base-font-size}rem;
|
||||||
|
padding-left: #{28 / $base-font-size}rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preference__option {
|
.preference__option {
|
||||||
@extend %preference-option;
|
@extend %preference-option;
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
padding-left: #{28 / $base-font-size}rem;
|
padding: 0;
|
||||||
&--selected {
|
&--selected {
|
||||||
@extend %preference-option--selected;
|
@extend %preference-option--selected;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.preference__options {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
width: #{70 / $base-font-size}rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,11 +38,54 @@
|
||||||
padding: #{8 / $base-font-size}rem #{20 / $base-font-size}rem;
|
padding: #{8 / $base-font-size}rem #{20 / $base-font-size}rem;
|
||||||
color: $light-inactive-text-color;
|
color: $light-inactive-text-color;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
position: relative;
|
||||||
&--selected {
|
&--selected {
|
||||||
background-color: $ide-border-color;
|
background-color: $ide-border-color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sidebar__file-item-name {
|
||||||
|
.sidebar__file-item--editing & {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar__file-item-show-options {
|
||||||
|
@extend %icon;
|
||||||
|
display: none;
|
||||||
|
.sidebar__file-item--selected & {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar__file-item-options {
|
||||||
|
@extend %modal;
|
||||||
|
position: absolute;
|
||||||
|
top: 95%;
|
||||||
|
left: 77%;
|
||||||
|
display: none;
|
||||||
|
z-index: 100;
|
||||||
|
padding: #{8 / $base-font-size}rem #{16 / $base-font-size}rem;
|
||||||
|
background-color: $light-modal-background-color;
|
||||||
|
z-index: 100;
|
||||||
|
.sidebar__file-item--open & {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar__file-item-input {
|
||||||
|
display: none;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
background-color: transparent;
|
||||||
|
max-width: 90%;
|
||||||
|
.sidebar__file-item--editing & {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar__contract {
|
.sidebar__contract {
|
||||||
@extend %icon;
|
@extend %icon;
|
||||||
height: #{14 / $base-font-size}rem;
|
height: #{14 / $base-font-size}rem;
|
||||||
|
|
|
@ -16,10 +16,15 @@
|
||||||
max-width: 45%;
|
max-width: 45%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
|
// temporary fix for safari
|
||||||
|
min-height: 75vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-holder {
|
.editor-holder {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
width: 100%;
|
||||||
|
position: absolute;
|
||||||
}
|
}
|
||||||
|
|
||||||
.preview-frame {
|
.preview-frame {
|
||||||
|
|
|
@ -46,7 +46,7 @@ export function getProjects(req, res) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
Project.find({user: req.user._id}) // eslint-disable-line no-underscore-dangle
|
Project.find({user: req.user._id}) // eslint-disable-line no-underscore-dangle
|
||||||
.sort('-createdAt')
|
.sort('-createdAt')
|
||||||
.select('name files _id createdAt updatedAt')
|
.select('name files id createdAt updatedAt')
|
||||||
.exec((err, projects) => {
|
.exec((err, projects) => {
|
||||||
res.json(projects);
|
res.json(projects);
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,7 +11,9 @@ export function createSession(req, res, next) {
|
||||||
if (innerErr) { return next(innerErr); }
|
if (innerErr) { return next(innerErr); }
|
||||||
return res.json({
|
return res.json({
|
||||||
email: req.user.email,
|
email: req.user.email,
|
||||||
username: req.user.username
|
username: req.user.username,
|
||||||
|
preferences: req.user.preferences,
|
||||||
|
id: req.user._id
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})(req, res, next);
|
})(req, res, next);
|
||||||
|
@ -21,7 +23,9 @@ export function getSession(req, res) {
|
||||||
if (req.user) {
|
if (req.user) {
|
||||||
return res.json({
|
return res.json({
|
||||||
email: req.user.email,
|
email: req.user.email,
|
||||||
username: req.user.username
|
username: req.user.username,
|
||||||
|
preferences: req.user.preferences,
|
||||||
|
id: req.user._id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return res.status(404).send({ message: 'Session does not exist' });
|
return res.status(404).send({ message: 'Session does not exist' });
|
||||||
|
|
|
@ -22,9 +22,33 @@ export function createUser(req, res, next) {
|
||||||
}
|
}
|
||||||
res.json({
|
res.json({
|
||||||
email: req.user.email,
|
email: req.user.email,
|
||||||
username: req.user.username
|
username: req.user.username,
|
||||||
|
preferences: req.user.preferences,
|
||||||
|
id: req.user._id
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updatePreferences(req, res) {
|
||||||
|
User.findById(req.user.id, (err, user) => {
|
||||||
|
if (err) {
|
||||||
|
return res.status(500).json({error: err});
|
||||||
|
}
|
||||||
|
if (!user){
|
||||||
|
return res.status(404).json({error: 'Document not found'});
|
||||||
|
}
|
||||||
|
|
||||||
|
const preferences = Object.assign({}, user.preferences, req.body.preferences);
|
||||||
|
user.preferences = preferences;
|
||||||
|
|
||||||
|
user.save((err) => {
|
||||||
|
if (err) {
|
||||||
|
return res.status(500).json({error: err});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.json(user.preferences);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,12 @@ const userSchema = new Schema({
|
||||||
github: { type: String },
|
github: { type: String },
|
||||||
email: { type: String, unique: true },
|
email: { type: String, unique: true },
|
||||||
tokens: Array,
|
tokens: Array,
|
||||||
admin: { type: Boolean, default: false }
|
preferences: {
|
||||||
|
fontSize: { type: Number, default: 18 },
|
||||||
|
indentationAmount: { type: Number, default: 2 },
|
||||||
|
isTabIndent: { type: Boolean, default: false },
|
||||||
|
autosave: { type: Boolean, default: true }
|
||||||
|
}
|
||||||
}, { timestamps: true });
|
}, { timestamps: true });
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +33,15 @@ userSchema.pre('save', function checkPassword(next) { // eslint-disable-line con
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
userSchema.virtual('id').get(function(){
|
||||||
|
return this._id.toHexString();
|
||||||
|
});
|
||||||
|
|
||||||
|
userSchema.set('toJSON', {
|
||||||
|
virtuals: true
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method for validating user's password.
|
* Helper method for validating user's password.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -4,4 +4,6 @@ const router = new Router();
|
||||||
|
|
||||||
router.route('/signup').post(UserController.createUser);
|
router.route('/signup').post(UserController.createUser);
|
||||||
|
|
||||||
|
router.route('/preferences').put(UserController.updatePreferences);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
Loading…
Reference in a new issue