2018-06-29 16:14:00 +00:00
|
|
|
import React from 'react'
|
|
|
|
import './Controls.css'
|
2018-09-11 14:14:46 +00:00
|
|
|
import emoji from 'react-easy-emoji'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { startConversation } from 'Actions/actions'
|
2018-09-11 16:45:54 +00:00
|
|
|
import { animated, Spring } from 'react-spring'
|
2018-09-12 13:07:46 +00:00
|
|
|
import { makeJsx } from 'Engine/evaluation'
|
2018-09-12 15:49:50 +00:00
|
|
|
import { createMarkdownDiv } from 'Engine/marked'
|
2018-09-12 17:12:59 +00:00
|
|
|
import { currentQuestionSelector } from '../selectors/analyseSelectors'
|
|
|
|
import { reject } from 'ramda'
|
|
|
|
|
|
|
|
function Controls({
|
|
|
|
blockingInputControls,
|
|
|
|
controls,
|
|
|
|
startConversation,
|
2018-09-13 13:55:55 +00:00
|
|
|
currentQuestion,
|
|
|
|
foldedSteps
|
2018-09-12 17:12:59 +00:00
|
|
|
}) {
|
|
|
|
let control =
|
|
|
|
!blockingInputControls &&
|
|
|
|
do {
|
|
|
|
let relevantControls = reject(
|
|
|
|
c => c.isInputControl && c.dottedName !== currentQuestion
|
|
|
|
)(controls)
|
|
|
|
|
|
|
|
relevantControls[0]
|
|
|
|
}
|
2018-06-29 16:14:00 +00:00
|
|
|
|
2018-09-11 14:14:46 +00:00
|
|
|
return (
|
2018-09-11 15:33:11 +00:00
|
|
|
<div id="controlsBlock">
|
2018-09-11 14:14:46 +00:00
|
|
|
{blockingInputControls && (
|
2018-09-11 16:45:54 +00:00
|
|
|
<p className="blockingControl">{blockingInputControls[0].message}</p>
|
|
|
|
)}
|
2018-09-12 15:33:27 +00:00
|
|
|
<Spring
|
|
|
|
to={{
|
|
|
|
height: control ? 'auto' : 0,
|
|
|
|
opacity: control ? 1 : 0
|
|
|
|
}}
|
2018-09-13 13:50:09 +00:00
|
|
|
delay={1200}
|
2018-09-12 15:33:27 +00:00
|
|
|
native>
|
|
|
|
{styles =>
|
|
|
|
!control ? null : (
|
|
|
|
<animated.div id="control" style={styles}>
|
|
|
|
<div id="controlContent">
|
|
|
|
{do {
|
2018-09-12 15:49:50 +00:00
|
|
|
let { level, message, solution, evaluated } = control
|
2018-09-12 15:33:27 +00:00
|
|
|
;<>
|
|
|
|
<h3
|
|
|
|
style={{
|
|
|
|
borderBottomColor:
|
|
|
|
level === 'avertissement' ? '#e67e22' : '#34495e'
|
|
|
|
}}>
|
|
|
|
{level === 'avertissement' ? 'Attention' : 'Information'}
|
|
|
|
</h3>
|
2018-09-12 15:49:50 +00:00
|
|
|
{message && createMarkdownDiv(message)}
|
|
|
|
{!message && (
|
|
|
|
<div id="controlExplanation">{makeJsx(evaluated)}</div>
|
|
|
|
)}
|
2018-09-13 13:55:55 +00:00
|
|
|
{solution &&
|
|
|
|
!foldedSteps.includes(solution.cible) && (
|
|
|
|
<div id="solution">
|
|
|
|
{emoji('💡')}
|
|
|
|
<button
|
|
|
|
key={solution.cible}
|
|
|
|
className="ui__ link-button"
|
|
|
|
onClick={() => startConversation(solution.cible)}>
|
|
|
|
{solution.texte}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
2018-09-12 15:33:27 +00:00
|
|
|
</>
|
|
|
|
}}
|
|
|
|
</div>
|
|
|
|
</animated.div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</Spring>
|
2018-09-11 14:14:46 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
2018-09-12 17:12:59 +00:00
|
|
|
(state, props) => ({
|
|
|
|
currentQuestion: currentQuestionSelector(state),
|
2018-09-13 13:55:55 +00:00
|
|
|
foldedSteps: state.conversationSteps.foldedSteps,
|
2018-09-12 17:12:59 +00:00
|
|
|
key: props.language
|
|
|
|
}),
|
2018-09-11 14:14:46 +00:00
|
|
|
{
|
|
|
|
startConversation
|
|
|
|
}
|
|
|
|
)(Controls)
|