2022-05-18 10:15:54 +02:00
|
|
|
import { useEffect, useRef, useState } from "react";
|
|
|
|
import styles from "../../styles/room/input.module.scss";
|
|
|
|
import { parseClassName } from "../../utils/utils.js";
|
2022-06-24 13:42:16 +02:00
|
|
|
import Input from "../Input.jsx";
|
|
|
|
import { AiOutlineCheck, AiOutlineClose } from "react-icons/ai";
|
2022-05-18 10:15:54 +02:00
|
|
|
|
2022-06-24 13:42:16 +02:00
|
|
|
export default function CorrectionInput({
|
|
|
|
inputData,
|
|
|
|
idInput,
|
|
|
|
idExo,
|
|
|
|
idCalcul,
|
|
|
|
correctionMenu,
|
|
|
|
setCorrectionMenu,
|
|
|
|
}) {
|
2022-05-18 10:15:54 +02:00
|
|
|
const [result, setResult] = useState({
|
|
|
|
correction: inputData.correction,
|
|
|
|
isCorrect: inputData.isCorrect,
|
|
|
|
});
|
2022-06-24 13:42:16 +02:00
|
|
|
const [fade, setFade] = useState(false);
|
|
|
|
useEffect(() => {
|
|
|
|
if (correctionMenu) {
|
|
|
|
setFade(true)
|
|
|
|
} else {
|
|
|
|
setFade(false);
|
|
|
|
}
|
|
|
|
}, [correctionMenu]);
|
2022-05-18 10:15:54 +02:00
|
|
|
return (
|
2022-06-24 13:42:16 +02:00
|
|
|
<div className={styles['correctionInput-main-container']}>
|
2022-05-18 10:15:54 +02:00
|
|
|
{correctionMenu && (
|
2022-06-24 13:42:16 +02:00
|
|
|
<div
|
|
|
|
className={styles["correction-menu"]}
|
|
|
|
style={{ opacity: !fade ? 0 : 1 }}
|
|
|
|
>
|
|
|
|
<Input
|
|
|
|
placeholder="Correction"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
2022-05-18 10:15:54 +02:00
|
|
|
type="text"
|
|
|
|
value={result.correction}
|
|
|
|
onChange={(e) => {
|
|
|
|
setResult({
|
|
|
|
correction: e.target.value,
|
|
|
|
isCorrect: inputData.value == e.target.value,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
/>
|
2022-06-24 13:42:16 +02:00
|
|
|
<div className={styles["icon-container"]}>
|
|
|
|
<AiOutlineCheck
|
|
|
|
title="Marquer comme juste"
|
|
|
|
className={parseClassName([
|
|
|
|
styles["icon"],
|
|
|
|
styles["icon-valid"],
|
|
|
|
!result.isCorrect ? styles["unactive"] : undefined,
|
|
|
|
])}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
setResult({ ...result, isCorrect: true });
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<AiOutlineClose
|
|
|
|
title="Marquer comme erroné"
|
|
|
|
className={parseClassName([
|
|
|
|
styles["icon"],
|
|
|
|
styles["icon-invalid"],
|
|
|
|
result.isCorrect ? styles["unactive"] : undefined,
|
|
|
|
])}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
setResult({ ...result, isCorrect: false });
|
|
|
|
}}
|
|
|
|
/>{" "}
|
|
|
|
</div>
|
2022-05-18 10:15:54 +02:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div
|
|
|
|
/* ref={ref} */
|
|
|
|
className={parseClassName([
|
|
|
|
styles["input"],
|
|
|
|
result.isCorrect ? styles["valid"] : styles["invalid"],
|
|
|
|
,
|
|
|
|
result.isCorrect == null ? styles["withoutCorrection"] : undefined,
|
|
|
|
])}
|
|
|
|
data-idexo={idExo}
|
|
|
|
data-idinput={idInput}
|
|
|
|
data-idcalcul={idCalcul}
|
|
|
|
data-iscorrect={result.isCorrect}
|
2022-06-24 13:42:16 +02:00
|
|
|
data-correction={result.correction}
|
2022-05-18 10:15:54 +02:00
|
|
|
id="correctionInput"
|
|
|
|
style={{ cursor: "pointer" }}
|
|
|
|
onClick={setCorrectionMenu}
|
|
|
|
>
|
2022-06-24 13:42:16 +02:00
|
|
|
{inputData.value}{" "}
|
|
|
|
{result.isCorrect == false &&
|
|
|
|
result.correction != "" &&
|
|
|
|
`-> ${result.correction}`}
|
2022-05-18 10:15:54 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|