import { useEffect, useState } from "react"; import { correctParcours, getCorrectionInfo, } from "../../requests/requests.room.js"; import { countOccurences, parseDate } from "../../utils/utils.js"; import Layout from "../Layout.js"; import CorrectionInput from "./CorrectionInput.jsx"; import InputExo from "./InputExo.jsx"; import ParcoursExo from "./ParcoursExo.jsx"; import styles from "../../styles/room/correction.module.scss"; import Back from "./back.jsx"; import { notificationService } from "../../services/notification.service.js"; export default function Correction({ owner, parcours_id, user_code, correct_code, room_code, }) { const [correctionMenu, setCorrectionMenu] = useState(null); const [correction, setCorrection] = useState(); useEffect(() => { getCorrectionInfo({ parcours_id: parcours_id, user_code: user_code, correct_code: correct_code, }).then((res) => { setCorrection(res); }); return () => { setCorrection(); }; }, []); useEffect(() => { document.addEventListener("click", (e) => { if (correctionMenu != null) { setCorrectionMenu(null); } }); }); return (
{correction && correction.parcours_name && (

{correction.parcours_name}{" "} {correction.challenger_name && ( - correction de{" "} {correction.challenger_name}{" "} le {parseDate(new Date(correction.endAt))} )}

= correction.success_condition ? styles["success"] : styles["fail"] : styles["notTrust"] } > {correction.note.value}/{correction.note.total} {correction.note.total != 20 && ` = ${ Math.round(((correction.note.value * 20) / correction.note.total) * 100) / 100 } / 20`} {/* Round 2 decimals */} {!correction.note.isTrust && " (Note provisoire)"}

)} {correction && ( <> {correction.result.map((exo) => { return (

Exercice {exo.order + 1}

{exo.exos .sort((a, b) => { return a.order - b.order; }) .map((ex) => { return (
{ex.calcul .replace("[", " [") .replace("]", "]") .split(" ") .map((c) => { if (c.startsWith("[") && c.endsWith("]")) { var idInput = parseInt( c.replace("[", "").replace("]", "") ); return ( i.order == idInput )[0] } idInput={idInput} idExo={exo.order} idCalcul={ex.order} correctionMenu={ correctionMenu == `${exo.order}.${ex.order}` } setCorrectionMenu={(e) => { e.stopPropagation(); if (owner) { setCorrectionMenu( correctionMenu == `${exo.order}.${ex.order}` ? null : `${exo.order}.${ex.order}` ); } }} /> ); } else return c + " "; })}
); })}
); })} {owner && ( )} )}
); }