Files
freeCodeCamp/common/app/routes/Hikes/components/Question.jsx

62 lines
1.4 KiB
React
Raw Normal View History

2015-07-09 00:29:29 -07:00
import React, { PropTypes } from 'react';
2015-07-15 10:54:03 -07:00
import { Col, Row, Panel } from 'react-bootstrap';
import { contain } from 'thundercats-react';
2015-07-09 00:29:29 -07:00
import stampit from 'react-stampit';
// import debugFactory from 'debug';
2015-07-15 10:54:03 -07:00
export default contain(
{
store: 'hikesStore',
map({ hikes, currentHike }) {
const { tests = [] } = currentHike;
return {
hikes,
currentHike,
tests
};
},
fetchAction: 'hikesActions.getHike',
getPayload({ currentHike, hikes, params: { dashedName } }) {
const filterRegex = new RegExp(dashedName, 'i');
if (currentHike && filterRegex.test(currentHike.dashedName)) {
return {
hikes: [],
isPrimed: true,
dashedName
};
}
return {
hikes,
isPrimed: false,
dashedName: dashedName
};
}
2015-07-09 00:29:29 -07:00
},
2015-07-15 10:54:03 -07:00
stampit(React, {
displayName: 'Question',
propTypes: {
params: PropTypes.object,
currentHike: PropTypes.object,
tests: PropTypes.array
},
render() {
const { tests } = this.props;
const { number = '1' } = this.props.params;
const [question, answer, info] = tests[number - 1] || [];
2015-07-09 00:29:29 -07:00
2015-07-15 10:54:03 -07:00
return (
<Col xs={ 12 }>
<Row>
<Panel>
<p>{ question }</p>
</Panel>
</Row>
</Col>
);
}
})
);