Files
freeCodeCamp/common/app/routes/challenges/components/Show.jsx

49 lines
1.2 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react';
import { compose } from 'redux';
import { contain } from 'redux-epic';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
2016-03-05 21:06:04 -08:00
import PureComponent from 'react-pure-render/component';
2016-05-13 22:34:40 -07:00
import Classic from './classic/Classic.jsx';
import Step from './step/Step.jsx';
import { fetchChallenge } from '../redux/actions';
2016-05-10 13:17:57 -07:00
import { challengeSelector } from '../redux/selectors';
const bindableActions = {
fetchChallenge
};
const mapStateToProps = createSelector(
challengeSelector,
2016-05-10 13:17:57 -07:00
state => state.challengesApp.challenge,
({ isStep }, challenge) => ({ challenge, isStep })
);
const fetchOptions = {
fetchAction: 'fetchChallenge',
getActionArgs({ params: { dashedName } }) {
return [ dashedName ];
},
isPrimed({ challenge }) {
2016-05-10 13:17:57 -07:00
return !!challenge;
}
};
export class Challenges extends PureComponent {
2016-03-05 21:06:04 -08:00
static displayName = 'Challenges';
2016-05-10 13:17:57 -07:00
static propTypes = { isStep: PropTypes.bool };
2016-03-05 21:06:04 -08:00
render() {
if (this.props.isStep) {
2016-05-10 13:17:57 -07:00
return <Step />;
}
2016-05-13 22:34:40 -07:00
return <Classic />;
2016-03-05 21:06:04 -08:00
}
}
export default compose(
connect(mapStateToProps, bindableActions),
contain(fetchOptions)
)(Challenges);