From 892fd64cf5eeda2cf3561033b771e63978de044a Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Wed, 15 Jul 2015 23:36:52 -0700 Subject: [PATCH] On successful answer take camper to next question --- .../app/routes/Hikes/components/Question.jsx | 52 +++++++++++++++++-- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/common/app/routes/Hikes/components/Question.jsx b/common/app/routes/Hikes/components/Question.jsx index b6d89351a1..0172c9b2e8 100644 --- a/common/app/routes/Hikes/components/Question.jsx +++ b/common/app/routes/Hikes/components/Question.jsx @@ -1,8 +1,16 @@ import React, { PropTypes } from 'react'; -import { Col, Row, Panel } from 'react-bootstrap'; -import { contain } from 'thundercats-react'; +import { Navigation } from 'react-router'; 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( { @@ -38,9 +46,27 @@ export default contain( propTypes: { params: PropTypes.object, currentHike: PropTypes.object, + dashedName: PropTypes.string, 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() { const { tests } = this.props; const { number = '1' } = this.props.params; @@ -48,14 +74,30 @@ export default contain( const [question, answer, info] = tests[number - 1] || []; return ( - +

{ question }

+ + + +
); } - }) + }).compose(Navigation) );