On successful answer take camper to next question
This commit is contained in:
@ -1,8 +1,16 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import { Col, Row, Panel } from 'react-bootstrap';
|
import { Navigation } from 'react-router';
|
||||||
import { contain } from 'thundercats-react';
|
|
||||||
import stampit from 'react-stampit';
|
import stampit from 'react-stampit';
|
||||||
// import debugFactory from 'debug';
|
import { contain } from 'thundercats-react';
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Col,
|
||||||
|
Row,
|
||||||
|
Panel
|
||||||
|
} from 'react-bootstrap';
|
||||||
|
import debugFactory from 'debug';
|
||||||
|
|
||||||
|
const debug = debugFactory('freecc:hikes');
|
||||||
|
|
||||||
export default contain(
|
export default contain(
|
||||||
{
|
{
|
||||||
@ -38,9 +46,27 @@ export default contain(
|
|||||||
propTypes: {
|
propTypes: {
|
||||||
params: PropTypes.object,
|
params: PropTypes.object,
|
||||||
currentHike: PropTypes.object,
|
currentHike: PropTypes.object,
|
||||||
|
dashedName: PropTypes.string,
|
||||||
tests: PropTypes.array
|
tests: PropTypes.array
|
||||||
},
|
},
|
||||||
|
|
||||||
|
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 }`);
|
||||||
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { tests } = this.props;
|
const { tests } = this.props;
|
||||||
const { number = '1' } = this.props.params;
|
const { number = '1' } = this.props.params;
|
||||||
@ -48,14 +74,30 @@ export default contain(
|
|||||||
const [question, answer, info] = tests[number - 1] || [];
|
const [question, answer, info] = tests[number - 1] || [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col xs={ 12 }>
|
<Col
|
||||||
|
xs={ 8 }
|
||||||
|
xsOffset={ 2 }>
|
||||||
<Row>
|
<Row>
|
||||||
<Panel>
|
<Panel>
|
||||||
<p>{ question }</p>
|
<p>{ question }</p>
|
||||||
</Panel>
|
</Panel>
|
||||||
|
<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>
|
||||||
</Row>
|
</Row>
|
||||||
</Col>
|
</Col>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
}).compose(Navigation)
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user