Feature use toast instead of modal for info
This commit is contained in:
@ -49,7 +49,6 @@ export default Store({
|
|||||||
const {
|
const {
|
||||||
toggleQuestions,
|
toggleQuestions,
|
||||||
fetchHikes,
|
fetchHikes,
|
||||||
hideInfo,
|
|
||||||
resetHike,
|
resetHike,
|
||||||
grabQuestion,
|
grabQuestion,
|
||||||
releaseQuestion,
|
releaseQuestion,
|
||||||
@ -61,7 +60,6 @@ export default Store({
|
|||||||
fromMany(
|
fromMany(
|
||||||
toggleQuestions,
|
toggleQuestions,
|
||||||
fetchHikes,
|
fetchHikes,
|
||||||
hideInfo,
|
|
||||||
resetHike,
|
resetHike,
|
||||||
grabQuestion,
|
grabQuestion,
|
||||||
releaseQuestion,
|
releaseQuestion,
|
||||||
|
@ -1,13 +1,7 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import { spring, Motion } from 'react-motion';
|
import { spring, Motion } from 'react-motion';
|
||||||
import { contain } from 'thundercats-react';
|
import { contain } from 'thundercats-react';
|
||||||
import {
|
import { Button, Col, Panel, Row } from 'react-bootstrap';
|
||||||
Button,
|
|
||||||
Col,
|
|
||||||
Modal,
|
|
||||||
Panel,
|
|
||||||
Row
|
|
||||||
} from 'react-bootstrap';
|
|
||||||
|
|
||||||
const answerThreshold = 100;
|
const answerThreshold = 100;
|
||||||
|
|
||||||
@ -23,7 +17,6 @@ export default contain(
|
|||||||
isCorrect = false,
|
isCorrect = false,
|
||||||
delta = [0, 0],
|
delta = [0, 0],
|
||||||
isPressed = false,
|
isPressed = false,
|
||||||
showInfo = false,
|
|
||||||
shake = false
|
shake = false
|
||||||
} = hikesApp;
|
} = hikesApp;
|
||||||
return {
|
return {
|
||||||
@ -33,7 +26,6 @@ export default contain(
|
|||||||
isCorrect,
|
isCorrect,
|
||||||
delta,
|
delta,
|
||||||
isPressed,
|
isPressed,
|
||||||
showInfo,
|
|
||||||
shake,
|
shake,
|
||||||
isSignedIn: !!username
|
isSignedIn: !!username
|
||||||
};
|
};
|
||||||
@ -49,13 +41,12 @@ export default contain(
|
|||||||
isCorrect: PropTypes.bool,
|
isCorrect: PropTypes.bool,
|
||||||
delta: PropTypes.array,
|
delta: PropTypes.array,
|
||||||
isPressed: PropTypes.bool,
|
isPressed: PropTypes.bool,
|
||||||
showInfo: PropTypes.bool,
|
|
||||||
shake: PropTypes.bool,
|
shake: PropTypes.bool,
|
||||||
isSignedIn: PropTypes.bool,
|
isSignedIn: PropTypes.bool,
|
||||||
hikesActions: PropTypes.object
|
hikesActions: PropTypes.object
|
||||||
},
|
},
|
||||||
|
|
||||||
handleMouseUp(e, answer) {
|
handleMouseUp(e, answer, info) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (!this.props.isPressed) {
|
if (!this.props.isPressed) {
|
||||||
return null;
|
return null;
|
||||||
@ -76,6 +67,7 @@ export default contain(
|
|||||||
delta,
|
delta,
|
||||||
currentQuestion,
|
currentQuestion,
|
||||||
isSignedIn,
|
isSignedIn,
|
||||||
|
info,
|
||||||
threshold: answerThreshold
|
threshold: answerThreshold
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -89,7 +81,7 @@ export default contain(
|
|||||||
hikesActions.moveQuestion({ e, delta });
|
hikesActions.moveQuestion({ e, delta });
|
||||||
},
|
},
|
||||||
|
|
||||||
onAnswer(answer, userAnswer) {
|
onAnswer(answer, userAnswer, info) {
|
||||||
const { isSignedIn, hike, currentQuestion, hikesActions } = this.props;
|
const { isSignedIn, hike, currentQuestion, hikesActions } = this.props;
|
||||||
return (e) => {
|
return (e) => {
|
||||||
if (e && e.preventDefault) {
|
if (e && e.preventDefault) {
|
||||||
@ -101,40 +93,15 @@ export default contain(
|
|||||||
userAnswer,
|
userAnswer,
|
||||||
currentQuestion,
|
currentQuestion,
|
||||||
hike,
|
hike,
|
||||||
|
info,
|
||||||
isSignedIn
|
isSignedIn
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
renderInfo(showInfo, info, hideInfo) {
|
renderQuestion(number, question, answer, shake, info) {
|
||||||
if (!info) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<Modal
|
|
||||||
backdrop={ true }
|
|
||||||
onHide={ hideInfo }
|
|
||||||
show={ showInfo }>
|
|
||||||
<Modal.Body>
|
|
||||||
<h3>
|
|
||||||
{ info }
|
|
||||||
</h3>
|
|
||||||
</Modal.Body>
|
|
||||||
<Modal.Footer>
|
|
||||||
<Button
|
|
||||||
block={ true }
|
|
||||||
bsSize='large'
|
|
||||||
onClick={ hideInfo }>
|
|
||||||
hide
|
|
||||||
</Button>
|
|
||||||
</Modal.Footer>
|
|
||||||
</Modal>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
renderQuestion(number, question, answer, shake) {
|
|
||||||
const { hikesActions } = this.props;
|
const { hikesActions } = this.props;
|
||||||
const mouseUp = e => this.handleMouseUp(e, answer);
|
const mouseUp = e => this.handleMouseUp(e, answer, info);
|
||||||
return ({ x }) => {
|
return ({ x }) => {
|
||||||
const style = {
|
const style = {
|
||||||
WebkitTransform: `translate3d(${ x }px, 0, 0)`,
|
WebkitTransform: `translate3d(${ x }px, 0, 0)`,
|
||||||
@ -164,34 +131,38 @@ export default contain(
|
|||||||
hike: { tests = [] } = {},
|
hike: { tests = [] } = {},
|
||||||
mouse: [x],
|
mouse: [x],
|
||||||
currentQuestion,
|
currentQuestion,
|
||||||
hikesActions,
|
|
||||||
showInfo,
|
|
||||||
shake
|
shake
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
const [ question, answer, info ] = tests[currentQuestion - 1] || [];
|
const [ question, answer, info ] = tests[currentQuestion - 1] || [];
|
||||||
|
const questionElement = this.renderQuestion(
|
||||||
|
currentQuestion,
|
||||||
|
question,
|
||||||
|
answer,
|
||||||
|
shake,
|
||||||
|
info
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col
|
<Col
|
||||||
onMouseUp={ e => this.handleMouseUp(e, answer) }
|
onMouseUp={ e => this.handleMouseUp(e, answer, info) }
|
||||||
xs={ 8 }
|
xs={ 8 }
|
||||||
xsOffset={ 2 }>
|
xsOffset={ 2 }>
|
||||||
<Row>
|
<Row>
|
||||||
<Motion style={{ x: spring(x, [120, 10]) }}>
|
<Motion style={{ x: spring(x, [120, 10]) }}>
|
||||||
{ this.renderQuestion(currentQuestion, question, answer, shake) }
|
{ questionElement }
|
||||||
</Motion>
|
</Motion>
|
||||||
{ this.renderInfo(showInfo, info, hikesActions.hideInfo) }
|
|
||||||
<Panel>
|
<Panel>
|
||||||
<Button
|
<Button
|
||||||
bsSize='large'
|
bsSize='large'
|
||||||
className='pull-left'
|
className='pull-left'
|
||||||
onClick={ this.onAnswer(answer, false) }>
|
onClick={ this.onAnswer(answer, false, info) }>
|
||||||
false
|
false
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
bsSize='large'
|
bsSize='large'
|
||||||
className='pull-right'
|
className='pull-right'
|
||||||
onClick={ this.onAnswer(answer, true) }>
|
onClick={ this.onAnswer(answer, true, info) }>
|
||||||
true
|
true
|
||||||
</Button>
|
</Button>
|
||||||
</Panel>
|
</Panel>
|
||||||
|
@ -99,15 +99,6 @@ export default Actions({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
hideInfo() {
|
|
||||||
return {
|
|
||||||
transform(state) {
|
|
||||||
const hikesApp = { ...state.hikesApp, showInfo: false };
|
|
||||||
return { ...state, hikesApp };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
grabQuestion(e) {
|
grabQuestion(e) {
|
||||||
let { pageX, pageY, touches } = e;
|
let { pageX, pageY, touches } = e;
|
||||||
if (touches) {
|
if (touches) {
|
||||||
@ -172,6 +163,7 @@ export default Actions({
|
|||||||
currentQuestion,
|
currentQuestion,
|
||||||
isSignedIn,
|
isSignedIn,
|
||||||
delta,
|
delta,
|
||||||
|
info,
|
||||||
threshold
|
threshold
|
||||||
}) {
|
}) {
|
||||||
if (typeof userAnswer === 'undefined') {
|
if (typeof userAnswer === 'undefined') {
|
||||||
@ -195,11 +187,20 @@ export default Actions({
|
|||||||
if (answer !== userAnswer) {
|
if (answer !== userAnswer) {
|
||||||
const startShake = {
|
const startShake = {
|
||||||
transform(state) {
|
transform(state) {
|
||||||
|
const toast = !info ?
|
||||||
|
state.toast :
|
||||||
|
{
|
||||||
|
id: state.toast && state.toast.id ? state.toast.id + 1 : 1,
|
||||||
|
title: 'Hint',
|
||||||
|
message: info,
|
||||||
|
type: 'info'
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
|
toast,
|
||||||
hikesApp: {
|
hikesApp: {
|
||||||
...state.hikesApp,
|
...state.hikesApp,
|
||||||
showInfo: true,
|
|
||||||
shake: true
|
shake: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -232,8 +233,7 @@ export default Actions({
|
|||||||
transform(state) {
|
transform(state) {
|
||||||
const hikesApp = {
|
const hikesApp = {
|
||||||
...state.hikesApp,
|
...state.hikesApp,
|
||||||
mouse: [0, 0],
|
mouse: [0, 0]
|
||||||
showInfo: false
|
|
||||||
};
|
};
|
||||||
return { ...state, hikesApp };
|
return { ...state, hikesApp };
|
||||||
}
|
}
|
||||||
@ -351,7 +351,6 @@ export default Actions({
|
|||||||
...state.hikesApp,
|
...state.hikesApp,
|
||||||
currentQuestion: 1,
|
currentQuestion: 1,
|
||||||
showQuestions: false,
|
showQuestions: false,
|
||||||
showInfo: false,
|
|
||||||
mouse: [0, 0],
|
mouse: [0, 0],
|
||||||
delta: [0, 0]
|
delta: [0, 0]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user