2015-07-09 00:29:29 -07:00
|
|
|
import React, { PropTypes } from 'react';
|
2015-07-15 23:36:52 -07:00
|
|
|
import { Navigation } from 'react-router';
|
2015-07-09 00:29:29 -07:00
|
|
|
import stampit from 'react-stampit';
|
2015-07-15 23:36:52 -07:00
|
|
|
import { contain } from 'thundercats-react';
|
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Col,
|
|
|
|
Row,
|
|
|
|
Panel
|
|
|
|
} from 'react-bootstrap';
|
|
|
|
import debugFactory from 'debug';
|
|
|
|
|
|
|
|
const debug = debugFactory('freecc:hikes');
|
2015-07-09 00:29:29 -07:00
|
|
|
|
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,
|
2015-07-15 23:36:52 -07:00
|
|
|
dashedName: PropTypes.string,
|
2015-07-15 10:54:03 -07:00
|
|
|
tests: PropTypes.array
|
|
|
|
},
|
|
|
|
|
2015-07-15 23:36:52 -07:00
|
|
|
onAnswer(answer, userAnswer, e) {
|
|
|
|
if (e && e.preventDefault) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
if (answer === userAnswer) {
|
|
|
|
debug('correct answer!');
|
|
|
|
return this.onCorrectAnswer();
|
|
|
|
}
|
|
|
|
return debug('incorrect');
|
|
|
|
},
|
|
|
|
|
|
|
|
onCorrectAnswer() {
|
|
|
|
const { dashedName, number } = this.props.params;
|
|
|
|
const nextQ = +number + 1;
|
|
|
|
this.transitionTo(`/hikes/${ dashedName }/questions/${ nextQ }`);
|
|
|
|
},
|
|
|
|
|
2015-07-15 10:54:03 -07:00
|
|
|
render() {
|
2015-07-15 21:56:06 -07:00
|
|
|
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 (
|
2015-07-15 23:36:52 -07:00
|
|
|
<Col
|
|
|
|
xs={ 8 }
|
|
|
|
xsOffset={ 2 }>
|
2015-07-15 10:54:03 -07:00
|
|
|
<Row>
|
|
|
|
<Panel>
|
|
|
|
<p>{ question }</p>
|
|
|
|
</Panel>
|
2015-07-15 23:36:52 -07:00
|
|
|
<Panel>
|
|
|
|
<Button
|
|
|
|
bsSize='large'
|
|
|
|
className='pull-left'
|
|
|
|
onClick={ this.onAnswer.bind(this, answer, false) }>
|
|
|
|
false
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
bsSize='large'
|
|
|
|
className='pull-right'
|
|
|
|
onClick={ this.onAnswer.bind(this, answer, true) }>
|
|
|
|
true
|
|
|
|
</Button>
|
|
|
|
</Panel>
|
2015-07-15 10:54:03 -07:00
|
|
|
</Row>
|
|
|
|
</Col>
|
|
|
|
);
|
|
|
|
}
|
2015-07-15 23:36:52 -07:00
|
|
|
}).compose(Navigation)
|
2015-07-15 10:54:03 -07:00
|
|
|
);
|