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-06-29 16:14:00 +00:00
|
|
|
|
2018-09-11 14:14:46 +00:00
|
|
|
function Controls({ blockingInputControls, controls, startConversation }) {
|
2018-09-12 15:33:27 +00:00
|
|
|
let control = !blockingInputControls && controls?.[0]
|
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
|
|
|
|
}}
|
|
|
|
delay={2000}
|
|
|
|
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-12 15:33:27 +00:00
|
|
|
{solution && (
|
|
|
|
<div id="solution">
|
|
|
|
{emoji('💡')}
|
|
|
|
<button
|
|
|
|
key={solution.cible}
|
|
|
|
className="ui__ link-button"
|
|
|
|
onClick={() => startConversation(solution.cible)}>
|
|
|
|
{solution.texte}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
}}
|
|
|
|
</div>
|
|
|
|
</animated.div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</Spring>
|
2018-09-11 14:14:46 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
(state, props) => ({ key: props.language }),
|
|
|
|
{
|
|
|
|
startConversation
|
|
|
|
}
|
|
|
|
)(Controls)
|