From c3ce578a26f2875a4ea021d2417c4d738b1fb965 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Tue, 21 Jul 2015 20:55:32 -0700 Subject: [PATCH] moving question to right answers true moving question to left answer false --- .../app/routes/Hikes/components/Question.jsx | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/common/app/routes/Hikes/components/Question.jsx b/common/app/routes/Hikes/components/Question.jsx index 50283b606c..4b90901ba1 100644 --- a/common/app/routes/Hikes/components/Question.jsx +++ b/common/app/routes/Hikes/components/Question.jsx @@ -11,6 +11,8 @@ import { } from 'react-bootstrap'; const debug = debugFactory('freecc:hikes'); +const ANSWER_THRESHOLD = 250; + export default React.createClass({ displayName: 'Question', @@ -62,13 +64,22 @@ export default React.createClass({ }); }, - handleMouseMove({ pageX, pageY }) { - const { isPressed, delta: [dx, dy] } = this.state; - if (isPressed) { - this.setState({ - mouse: [pageX - dx, pageY - dy] - }); - } + handleMouseMove(answer) { + return ({ pageX, pageY }) => { + const { isPressed, delta: [dx, dy] } = this.state; + if (isPressed) { + const mouse = [pageX - dx, pageY - dy]; + if (mouse[0] >= ANSWER_THRESHOLD) { + this.handleMouseUp(); + return this.onAnswer(answer, true)(); + } + if (mouse[0] <= -ANSWER_THRESHOLD) { + this.handleMouseUp(); + return this.onAnswer(answer, false)(); + } + this.setState({ mouse }); + } + }; }, hideInfo() { @@ -162,7 +173,7 @@ export default React.createClass({ ); }, - renderQuestion(question, shake) { + renderQuestion(question, answer, shake) { return ({ val: { x } }) => { const style = { WebkitTransform: `translate3d(${ x }px, 0, 0)`, @@ -170,10 +181,10 @@ export default React.createClass({ }; return (

{ question }

@@ -196,7 +207,7 @@ export default React.createClass({ xsOffset={ 2 }> - { this.renderQuestion(question, shake) } + { this.renderQuestion(question, answer, shake) } { this.renderInfo(showInfo, info) }