Add code storage on code execution

This commit is contained in:
Berkeley Martinez
2016-05-27 22:07:10 -07:00
parent 8bf27f9834
commit 7c691b5532
7 changed files with 98 additions and 8 deletions

View File

@@ -8,14 +8,24 @@ import Editor from './Editor.jsx';
import SidePanel from './Side-Panel.jsx';
import Preview from './Preview.jsx';
import { challengeSelector } from '../../redux/selectors';
import { executeChallenge, updateMain, updateFile } from '../../redux/actions';
import {
executeChallenge,
updateMain,
updateFile,
loadCode
} from '../../redux/actions';
const mapStateToProps = createSelector(
challengeSelector,
state => state.challengesApp.tests,
state => state.challengesApp.files,
state => state.challengesApp.key,
({ challenge, showPreview, mode }, tests, files = {}, key = '') => ({
(
{ showPreview, mode },
tests,
files = {},
key = ''
) => ({
content: files[key] && files[key].contents || '',
file: files[key],
showPreview,
@@ -24,7 +34,12 @@ const mapStateToProps = createSelector(
})
);
const bindableActions = { executeChallenge, updateFile, updateMain };
const bindableActions = {
executeChallenge,
updateFile,
updateMain,
loadCode
};
export class Challenge extends PureComponent {
static displayName = 'Challenge';
@@ -35,12 +50,15 @@ export class Challenge extends PureComponent {
mode: PropTypes.string,
updateFile: PropTypes.func,
executeChallenge: PropTypes.func,
updateMain: PropTypes.func
updateMain: PropTypes.func,
loadCode: PropTypes.func
};
componentDidMount() {
this.props.loadCode();
this.props.updateMain();
}
renderPreview(showPreview) {
if (!showPreview) {
return null;