forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial dynamic challenge rendering
- Loading branch information
Berkeley Martinez
authored and
Berkeley Martinez
committed
Jul 29, 2016
1 parent
59dcabb
commit a0f6ecf
Showing
20 changed files
with
376 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,72 @@ | ||
import React from 'react'; | ||
|
||
import React, { PropTypes } from 'react'; | ||
import { compose } from 'redux'; | ||
import { contain } from 'redux-epic'; | ||
import { connect } from 'react-redux'; | ||
import { createSelector } from 'reselect'; | ||
import PureComponent from 'react-pure-render/component'; | ||
|
||
// import Challenge from './Challenge.jsx'; | ||
import Challenge from './Challenge.jsx'; | ||
import Step from './step/Step.jsx'; | ||
import { fetchChallenge } from '../../../redux/actions'; | ||
import { STEP, HTML } from '../../../utils/challengeTypes'; | ||
|
||
const bindableActions = { | ||
fetchChallenge | ||
}; | ||
|
||
const challengeSelector = createSelector( | ||
state => state.challengesApp.challenge, | ||
state => state.entities.challenge, | ||
(challengeName, challengeMap) => { | ||
const challenge = challengeMap[challengeName]; | ||
return { | ||
challenge: challenge, | ||
showPreview: !!challenge && challenge.challengeType === HTML, | ||
isStep: !!challenge && challenge.challengeType === STEP, | ||
mode: !!challenge && challenge.challengeType === HTML ? | ||
'text/html' : | ||
'javascript' | ||
}; | ||
} | ||
); | ||
|
||
const mapStateToProps = createSelector( | ||
challengeSelector, | ||
state => state.challengesApp.content, | ||
(challengeProps, content) => ({ | ||
...challengeProps, | ||
content | ||
}) | ||
); | ||
|
||
// <Challenge showPreview={ false } /> | ||
export default class extends PureComponent { | ||
const fetchOptions = { | ||
fetchAction: 'fetchChallenge', | ||
getActionArgs({ params: { dashedName } }) { | ||
return [ dashedName ]; | ||
}, | ||
isPrimed({ challenge }) { | ||
return challenge; | ||
} | ||
}; | ||
|
||
export class Challenges extends PureComponent { | ||
static displayName = 'Challenges'; | ||
static propTypes = {}; | ||
static propTypes = { | ||
challenge: PropTypes.object, | ||
showPreview: PropTypes.bool, | ||
mode: PropTypes.string, | ||
isStep: PropTypes.bool | ||
}; | ||
|
||
render() { | ||
return ( | ||
<Step /> | ||
); | ||
if (this.props.isStep) { | ||
return <Step { ...this.props }/>; | ||
} | ||
return <Challenge { ...this.props }/>; | ||
} | ||
} | ||
|
||
export default compose( | ||
connect(mapStateToProps, bindableActions), | ||
contain(fetchOptions) | ||
)(Challenges); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.