Fix(challenges): load stored code on challenge change

This commit is contained in:
Berkeley Martinez
2016-08-13 15:18:33 -07:00
parent b1d04077d9
commit 1c460e3319

View File

@ -18,15 +18,18 @@ import {
const mapStateToProps = createSelector(
challengeSelector,
state => state.challengesApp.id,
state => state.challengesApp.tests,
state => state.challengesApp.files,
state => state.challengesApp.key,
(
{ showPreview, mode },
id,
tests,
files = {},
key = ''
) => ({
id,
content: files[key] && files[key].contents || '',
file: files[key],
showPreview,
@ -46,6 +49,7 @@ export class Challenge extends PureComponent {
static displayName = 'Challenge';
static propTypes = {
id: PropTypes.string,
showPreview: PropTypes.bool,
content: PropTypes.string,
mode: PropTypes.string,
@ -60,6 +64,12 @@ export class Challenge extends PureComponent {
this.props.updateMain();
}
componentWillReceiveProps(nextProps) {
if (this.props.id !== nextProps.id) {
this.props.loadCode();
}
}
renderPreview(showPreview) {
if (!showPreview) {
return null;