2016-03-05 21:06:04 -08:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-05-10 13:17:57 -07:00
|
|
|
import { connect } from 'react-redux';
|
2016-03-05 21:06:04 -08:00
|
|
|
import { Col } from 'react-bootstrap';
|
2016-05-10 13:17:57 -07:00
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
import PureComponent from 'react-pure-render/component';
|
2016-03-05 21:06:04 -08:00
|
|
|
|
|
|
|
import Editor from './Editor.jsx';
|
|
|
|
import SidePanel from './Side-Panel.jsx';
|
|
|
|
import Preview from './Preview.jsx';
|
2016-05-13 22:34:40 -07:00
|
|
|
import { challengeSelector } from '../../redux/selectors';
|
|
|
|
import { updateFile } from '../../redux/actions';
|
2016-03-05 21:06:04 -08:00
|
|
|
|
2016-05-10 13:17:57 -07:00
|
|
|
const mapStateToProps = createSelector(
|
|
|
|
challengeSelector,
|
2016-05-13 20:04:56 -07:00
|
|
|
state => state.challengesApp.tests,
|
2016-05-11 23:16:03 -07:00
|
|
|
state => state.challengesApp.files,
|
|
|
|
state => state.challengesApp.path,
|
2016-05-13 20:04:56 -07:00
|
|
|
({ challenge, showPreview, mode }, tests, files = {}, path = '') => ({
|
|
|
|
content: files[path] && files[path].contents || '',
|
2016-05-13 20:36:54 -07:00
|
|
|
file: files[path],
|
2016-05-10 13:17:57 -07:00
|
|
|
showPreview,
|
2016-05-13 20:04:56 -07:00
|
|
|
mode,
|
|
|
|
tests
|
2016-05-10 13:17:57 -07:00
|
|
|
})
|
|
|
|
);
|
|
|
|
|
2016-05-13 20:36:54 -07:00
|
|
|
const bindableActions = { updateFile };
|
|
|
|
|
2016-05-10 13:17:57 -07:00
|
|
|
export class Challenge extends PureComponent {
|
2016-03-05 21:06:04 -08:00
|
|
|
static displayName = 'Challenge';
|
|
|
|
|
|
|
|
static propTypes = {
|
2016-05-09 13:42:39 -07:00
|
|
|
showPreview: PropTypes.bool,
|
2016-05-13 20:04:56 -07:00
|
|
|
content: PropTypes.string,
|
|
|
|
mode: PropTypes.string
|
2016-03-05 21:06:04 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
renderPreview(showPreview) {
|
|
|
|
if (!showPreview) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Col
|
|
|
|
lg={ 3 }
|
2016-05-09 13:42:39 -07:00
|
|
|
md={ 4 }>
|
2016-03-05 21:06:04 -08:00
|
|
|
<Preview />
|
|
|
|
</Col>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-05-13 20:36:54 -07:00
|
|
|
const {
|
|
|
|
content,
|
|
|
|
updateFile,
|
|
|
|
file,
|
|
|
|
mode,
|
|
|
|
showPreview
|
|
|
|
} = this.props;
|
2016-03-05 21:06:04 -08:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Col
|
|
|
|
lg={ 3 }
|
|
|
|
md={ showPreview ? 3 : 4 }>
|
2016-05-13 20:04:56 -07:00
|
|
|
<SidePanel />
|
2016-03-05 21:06:04 -08:00
|
|
|
</Col>
|
|
|
|
<Col
|
|
|
|
lg={ showPreview ? 6 : 9 }
|
|
|
|
md={ showPreview ? 5 : 8 }>
|
2016-05-09 13:42:39 -07:00
|
|
|
<Editor
|
|
|
|
content={ content }
|
|
|
|
mode={ mode }
|
2016-05-13 20:36:54 -07:00
|
|
|
updateFile={ content => updateFile(content, file) }
|
2016-05-09 13:42:39 -07:00
|
|
|
/>
|
2016-03-05 21:06:04 -08:00
|
|
|
</Col>
|
|
|
|
{ this.renderPreview(showPreview) }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-05-10 13:17:57 -07:00
|
|
|
|
2016-05-13 20:36:54 -07:00
|
|
|
export default connect(mapStateToProps, bindableActions)(Challenge);
|