2016-03-05 21:06:04 -08:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-07-01 19:32:02 -07:00
|
|
|
import ReactDom from 'react-dom';
|
2016-03-05 21:06:04 -08:00
|
|
|
import { createSelector } from 'reselect';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PureComponent from 'react-pure-render/component';
|
|
|
|
import { Col, Row } from 'react-bootstrap';
|
|
|
|
|
2017-01-26 21:07:22 -08:00
|
|
|
import TestSuite from '../Test-Suite.jsx';
|
|
|
|
import Output from '../Output.jsx';
|
2016-03-05 21:06:04 -08:00
|
|
|
import ToolPanel from './Tool-Panel.jsx';
|
2016-05-13 22:34:40 -07:00
|
|
|
import { challengeSelector } from '../../redux/selectors';
|
2016-07-11 21:54:55 -07:00
|
|
|
import {
|
|
|
|
openBugModal,
|
|
|
|
updateHint,
|
2016-08-16 15:59:23 -07:00
|
|
|
executeChallenge,
|
|
|
|
unlockUntrustedCode
|
2016-07-11 21:54:55 -07:00
|
|
|
} from '../../redux/actions';
|
2017-01-26 21:07:22 -08:00
|
|
|
import { descriptionRegex } from '../../utils';
|
2016-07-06 11:47:16 -07:00
|
|
|
import { makeToast } from '../../../../toasts/redux/actions';
|
2016-03-05 21:06:04 -08:00
|
|
|
|
2016-11-08 17:26:58 -08:00
|
|
|
const mapDispatchToProps = {
|
2016-07-11 17:44:50 -07:00
|
|
|
makeToast,
|
|
|
|
executeChallenge,
|
|
|
|
updateHint,
|
2016-08-16 15:59:23 -07:00
|
|
|
openBugModal,
|
|
|
|
unlockUntrustedCode
|
2016-07-11 17:44:50 -07:00
|
|
|
};
|
2016-03-05 21:06:04 -08:00
|
|
|
const mapStateToProps = createSelector(
|
2016-05-13 20:04:56 -07:00
|
|
|
challengeSelector,
|
2016-03-05 21:06:04 -08:00
|
|
|
state => state.app.windowHeight,
|
|
|
|
state => state.app.navHeight,
|
2016-05-13 20:04:56 -07:00
|
|
|
state => state.challengesApp.tests,
|
2016-05-27 17:11:25 -07:00
|
|
|
state => state.challengesApp.output,
|
2016-06-14 18:47:43 -07:00
|
|
|
state => state.challengesApp.hintIndex,
|
2016-08-16 15:59:23 -07:00
|
|
|
state => state.challengesApp.isCodeLocked,
|
2016-11-08 17:26:58 -08:00
|
|
|
state => state.challengesApp.helpChatRoom,
|
2016-05-13 20:04:56 -07:00
|
|
|
(
|
2016-10-29 00:46:45 +01:00
|
|
|
{
|
|
|
|
challenge: {
|
|
|
|
description,
|
|
|
|
hints = []
|
|
|
|
} = {},
|
|
|
|
title
|
|
|
|
},
|
2016-05-13 20:04:56 -07:00
|
|
|
windowHeight,
|
|
|
|
navHeight,
|
|
|
|
tests,
|
2016-06-14 18:47:43 -07:00
|
|
|
output,
|
2016-08-16 15:59:23 -07:00
|
|
|
hintIndex,
|
2016-11-08 17:26:58 -08:00
|
|
|
isCodeLocked,
|
|
|
|
helpChatRoom
|
2016-05-13 20:04:56 -07:00
|
|
|
) => ({
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
height: windowHeight - navHeight - 20,
|
|
|
|
tests,
|
2016-06-14 18:47:43 -07:00
|
|
|
output,
|
2016-08-16 15:59:23 -07:00
|
|
|
hint: hints[hintIndex],
|
2016-11-08 17:26:58 -08:00
|
|
|
isCodeLocked,
|
|
|
|
helpChatRoom
|
2016-05-13 20:04:56 -07:00
|
|
|
})
|
2016-03-05 21:06:04 -08:00
|
|
|
);
|
2017-01-12 06:54:43 +00:00
|
|
|
const propTypes = {
|
|
|
|
description: PropTypes.arrayOf(PropTypes.string),
|
|
|
|
executeChallenge: PropTypes.func,
|
|
|
|
height: PropTypes.number,
|
|
|
|
helpChatRoom: PropTypes.string,
|
|
|
|
hint: PropTypes.string,
|
|
|
|
isCodeLocked: PropTypes.bool,
|
|
|
|
makeToast: PropTypes.func,
|
|
|
|
openBugModal: PropTypes.func,
|
|
|
|
output: PropTypes.string,
|
|
|
|
tests: PropTypes.arrayOf(PropTypes.object),
|
|
|
|
title: PropTypes.string,
|
|
|
|
unlockUntrustedCode: PropTypes.func,
|
|
|
|
updateHint: PropTypes.func
|
|
|
|
};
|
2016-03-05 21:06:04 -08:00
|
|
|
|
|
|
|
export class SidePanel extends PureComponent {
|
|
|
|
|
2017-01-26 21:07:22 -08:00
|
|
|
renderDescription(description = [ 'Happy Coding!' ]) {
|
2016-03-05 21:06:04 -08:00
|
|
|
return description.map((line, index) => {
|
|
|
|
if (descriptionRegex.test(line)) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
dangerouslySetInnerHTML={{ __html: line }}
|
2016-06-14 18:47:43 -07:00
|
|
|
key={ line.slice(-6) + index }
|
|
|
|
/>
|
2016-03-05 21:06:04 -08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<p
|
|
|
|
className='wrappable'
|
|
|
|
dangerouslySetInnerHTML= {{ __html: line }}
|
2016-06-14 18:47:43 -07:00
|
|
|
key={ line.slice(-6) + index }
|
|
|
|
/>
|
2016-03-05 21:06:04 -08:00
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-07-01 19:32:02 -07:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (this.props.title !== nextProps.title) {
|
|
|
|
ReactDom.findDOMNode(this).scrollTop = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 21:06:04 -08:00
|
|
|
render() {
|
2016-05-27 17:11:25 -07:00
|
|
|
const {
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
height,
|
|
|
|
tests = [],
|
2016-06-14 18:47:43 -07:00
|
|
|
output,
|
|
|
|
hint,
|
|
|
|
executeChallenge,
|
|
|
|
updateHint,
|
2016-07-11 17:44:50 -07:00
|
|
|
makeToast,
|
2016-11-08 17:26:58 -08:00
|
|
|
helpChatRoom,
|
2016-08-16 15:59:23 -07:00
|
|
|
openBugModal,
|
|
|
|
isCodeLocked,
|
|
|
|
unlockUntrustedCode
|
2016-05-27 17:11:25 -07:00
|
|
|
} = this.props;
|
2016-07-30 01:04:40 +05:30
|
|
|
const style = {};
|
2016-03-05 21:06:04 -08:00
|
|
|
if (height) {
|
|
|
|
style.height = height + 'px';
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<div
|
2016-07-30 01:04:40 +05:30
|
|
|
className='challenges-instructions-panel'
|
2016-03-05 21:06:04 -08:00
|
|
|
ref='panel'
|
2016-06-14 18:47:43 -07:00
|
|
|
style={ style }
|
|
|
|
>
|
2016-03-05 21:06:04 -08:00
|
|
|
<div>
|
|
|
|
<h4 className='text-center challenge-instructions-title'>
|
2016-05-13 20:04:56 -07:00
|
|
|
{ title || 'Happy Coding!' }
|
2016-03-05 21:06:04 -08:00
|
|
|
</h4>
|
|
|
|
<hr />
|
|
|
|
<Row>
|
|
|
|
<Col
|
|
|
|
className='challenge-instructions'
|
2016-06-14 18:47:43 -07:00
|
|
|
xs={ 12 }
|
|
|
|
>
|
2017-01-26 21:07:22 -08:00
|
|
|
{ this.renderDescription(description) }
|
2016-03-05 21:06:04 -08:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</div>
|
2016-06-14 18:47:43 -07:00
|
|
|
<ToolPanel
|
|
|
|
executeChallenge={ executeChallenge }
|
2016-11-08 17:26:58 -08:00
|
|
|
helpChatRoom={ helpChatRoom }
|
2016-06-14 18:47:43 -07:00
|
|
|
hint={ hint }
|
2016-08-16 15:59:23 -07:00
|
|
|
isCodeLocked={ isCodeLocked }
|
2016-06-14 18:47:43 -07:00
|
|
|
makeToast={ makeToast }
|
2016-07-11 21:54:55 -07:00
|
|
|
openBugModal={ openBugModal }
|
2016-08-16 15:59:23 -07:00
|
|
|
unlockUntrustedCode={ unlockUntrustedCode }
|
2016-06-14 18:47:43 -07:00
|
|
|
updateHint={ updateHint }
|
|
|
|
/>
|
2017-01-26 21:07:22 -08:00
|
|
|
<Output
|
|
|
|
defaultOutput={
|
|
|
|
`/**
|
|
|
|
* Your output will go here.
|
|
|
|
* Any console.log() statements
|
|
|
|
* will appear in here as well.
|
|
|
|
*/`
|
|
|
|
}
|
|
|
|
output={ output }
|
|
|
|
/>
|
2016-03-05 21:06:04 -08:00
|
|
|
<br />
|
2016-05-27 22:21:52 -07:00
|
|
|
<TestSuite tests={ tests } />
|
2016-03-05 21:06:04 -08:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-12 06:54:43 +00:00
|
|
|
SidePanel.displayName = 'SidePanel';
|
|
|
|
SidePanel.propTypes = propTypes;
|
|
|
|
|
2016-06-14 18:47:43 -07:00
|
|
|
export default connect(
|
|
|
|
mapStateToProps,
|
2016-11-08 17:26:58 -08:00
|
|
|
mapDispatchToProps
|
2016-06-14 18:47:43 -07:00
|
|
|
)(SidePanel);
|