2019-06-05 14:57:08 +00:00
|
|
|
|
import { goToQuestion, hideControl } from 'Actions/actions'
|
2020-04-23 07:30:03 +00:00
|
|
|
|
import { useControls, useInversionFail } from 'Components/utils/EngineContext'
|
2018-11-09 11:36:29 +00:00
|
|
|
|
import { makeJsx } from 'Engine/evaluation'
|
2018-06-29 16:14:00 +00:00
|
|
|
|
import React from 'react'
|
2018-09-11 14:14:46 +00:00
|
|
|
|
import emoji from 'react-easy-emoji'
|
2019-09-11 08:06:51 +00:00
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2020-02-09 15:03:28 +00:00
|
|
|
|
import { useDispatch, useSelector } from 'react-redux'
|
|
|
|
|
import { RootState } from 'Reducers/rootReducer'
|
2019-04-03 09:16:09 +00:00
|
|
|
|
import animate from 'Ui/animate'
|
2018-11-09 11:36:29 +00:00
|
|
|
|
import './Controls.css'
|
2019-07-09 13:35:09 +00:00
|
|
|
|
import { Markdown } from './utils/markdown'
|
2020-01-14 14:13:37 +00:00
|
|
|
|
import { ScrollToElement } from './utils/Scroll'
|
2020-04-23 07:30:03 +00:00
|
|
|
|
import { answeredQuestionsSelector } from 'Selectors/simulationSelectors'
|
2018-09-12 17:12:59 +00:00
|
|
|
|
|
2020-02-09 15:03:28 +00:00
|
|
|
|
export default function Controls() {
|
2019-09-11 08:06:51 +00:00
|
|
|
|
const { t } = useTranslation()
|
2020-04-23 07:30:03 +00:00
|
|
|
|
const answeredQuestions = useSelector(answeredQuestionsSelector)
|
|
|
|
|
const controls = useControls()
|
|
|
|
|
const inversionFail = useInversionFail()
|
2020-02-09 15:03:28 +00:00
|
|
|
|
const hiddenControls = useSelector(
|
|
|
|
|
(state: RootState) => state.simulation?.hiddenControls
|
|
|
|
|
)
|
|
|
|
|
const dispatch = useDispatch()
|
|
|
|
|
|
2019-05-20 16:04:39 +00:00
|
|
|
|
if (!controls) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
2020-02-09 15:03:28 +00:00
|
|
|
|
let messages = inversionFail
|
|
|
|
|
? [
|
|
|
|
|
{
|
|
|
|
|
message: t([
|
|
|
|
|
'simulateurs.inversionFail',
|
|
|
|
|
'Le montant saisi ne permet pas de calculer un résultat, nous vous invitons à essayer une autre valeur.'
|
|
|
|
|
]),
|
|
|
|
|
level: 'avertissement'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
: controls
|
2019-12-16 14:13:22 +00:00
|
|
|
|
if (!messages?.length) return null
|
2019-04-10 13:41:56 +00:00
|
|
|
|
|
2018-09-11 14:14:46 +00:00
|
|
|
|
return (
|
2018-09-11 15:33:11 +00:00
|
|
|
|
<div id="controlsBlock">
|
2019-04-03 09:16:09 +00:00
|
|
|
|
<ul style={{ margin: 0, padding: 0 }}>
|
2019-04-09 15:50:36 +00:00
|
|
|
|
{messages.map(({ level, test, message, solution, evaluated }) =>
|
2020-02-09 15:03:28 +00:00
|
|
|
|
hiddenControls?.includes(test) ? null : (
|
2019-12-16 14:13:22 +00:00
|
|
|
|
<animate.fromTop key={message}>
|
2019-04-17 09:13:35 +00:00
|
|
|
|
<li key={test}>
|
|
|
|
|
<div className="control">
|
|
|
|
|
{emoji(level == 'avertissement' ? '⚠️' : 'ℹ️')}
|
|
|
|
|
<div className="controlText ui__ card">
|
|
|
|
|
{message ? (
|
2019-07-09 13:35:09 +00:00
|
|
|
|
<Markdown source={message} />
|
2019-04-17 09:13:35 +00:00
|
|
|
|
) : (
|
2019-12-16 14:13:22 +00:00
|
|
|
|
<span id="controlExplanation">{makeJsx(evaluated)}</span>
|
|
|
|
|
)}
|
2019-03-25 17:03:25 +00:00
|
|
|
|
|
2020-04-23 07:30:03 +00:00
|
|
|
|
{solution && !answeredQuestions?.includes(solution.cible) && (
|
2019-04-17 09:13:35 +00:00
|
|
|
|
<div>
|
|
|
|
|
<button
|
|
|
|
|
key={solution.cible}
|
|
|
|
|
className="ui__ link-button"
|
2020-02-09 15:03:28 +00:00
|
|
|
|
onClick={() => dispatch(goToQuestion(solution.cible))}
|
2019-12-16 14:13:22 +00:00
|
|
|
|
>
|
2019-04-17 09:13:35 +00:00
|
|
|
|
{solution.texte}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
<button
|
|
|
|
|
className="hide"
|
|
|
|
|
aria-label="close"
|
2020-02-09 15:03:28 +00:00
|
|
|
|
onClick={() => dispatch(hideControl(test))}
|
2019-12-16 14:13:22 +00:00
|
|
|
|
>
|
2019-04-17 09:13:35 +00:00
|
|
|
|
×
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2019-04-03 09:16:09 +00:00
|
|
|
|
</div>
|
2019-04-17 09:13:35 +00:00
|
|
|
|
</li>
|
2020-01-14 14:13:37 +00:00
|
|
|
|
<ScrollToElement />
|
2019-04-17 09:13:35 +00:00
|
|
|
|
</animate.fromTop>
|
2018-11-15 13:38:13 +00:00
|
|
|
|
)
|
|
|
|
|
)}
|
|
|
|
|
</ul>
|
2018-09-11 14:14:46 +00:00
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|