mon-entreprise/source/components/Controls.js

79 lines
2.0 KiB
JavaScript
Raw Normal View History

import React from 'react'
import './Controls.css'
import emoji from 'react-easy-emoji'
import { connect } from 'react-redux'
import { startConversation } from 'Actions/actions'
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'
import { currentQuestionSelector } from '../selectors/analyseSelectors'
import { reject } from 'ramda'
2018-10-02 14:52:27 +00:00
import withColours from './utils/withColours'
function Controls({
blockingInputControls,
controls,
startConversation,
currentQuestion,
2018-10-02 14:52:27 +00:00
foldedSteps,
colours
}) {
return (
2018-09-11 15:33:11 +00:00
<div id="controlsBlock">
{blockingInputControls && (
<p className="blockingControl">{blockingInputControls[0].message}</p>
)}
2018-10-02 14:52:27 +00:00
{!blockingInputControls && (
<>
<ul>
{controls.map(control => (
<li
key={control.si}
className="control"
style={{ background: colours.lightenColour(45) }}>
{do {
2018-09-12 15:49:50 +00:00
let { level, message, solution, evaluated } = control
;<>
2018-10-02 14:52:27 +00:00
{emoji(level == 'avertissement' ? '⚠️' : '')}
<div className="controlText">
{message && createMarkdownDiv(message)}
{!message && (
<span id="controlExplanation">
{makeJsx(evaluated)}
</span>
)}
2018-10-02 14:52:27 +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>
)}
</div>
</>
}}
2018-10-02 14:52:27 +00:00
</li>
))}
</ul>
</>
)}
</div>
)
}
export default connect(
(state, props) => ({
currentQuestion: currentQuestionSelector(state),
foldedSteps: state.conversationSteps.foldedSteps,
key: props.language
}),
{
startConversation
}
2018-10-02 14:52:27 +00:00
)(withColours(Controls))