Download source/src/ui/ExamPanel.jsx from FormaLau/microduck-reachy-simulator: direct link, hf CLI and curl.
- Browser
- Download file 5.95 kB
-
https://huggingface.co/spaces/FormaLau/microduck-reachy-simulator/resolve/main/source/src/ui/ExamPanel.jsx
- Command line
-
hf download hf://spaces/FormaLau/microduck-reachy-simulator/source/src/ui/ExamPanel.jsx
-
curl -L -o ExamPanel.jsx https://huggingface.co/spaces/FormaLau/microduck-reachy-simulator/resolve/main/source/src/ui/ExamPanel.jsx
5.95 kB
| import { useState } from 'react'; | |
| import { highlightC } from '../training/cSyntaxHighlight.js'; | |
| export function ExamPanel({ exam, language }) { | |
| const [student, setStudent] = useState(''), [code, setCode] = useState(''); | |
| const { t } = exam; | |
| const locale = language === 'fr' ? 'fr' : 'en'; | |
| return <section className="exercise-panel-content exam-panel" aria-label={t('Évaluation', 'Assessment')}> | |
| {!exam.auth ? <form onSubmit={async event => { event.preventDefault(); if (await exam.login(student, code)) setCode(''); }}> | |
| <label>{t('Nom et prénom', 'Full name')}<input autoComplete="name" value={student} maxLength={100} required disabled={exam.working} onChange={e => setStudent(e.target.value)} /></label> | |
| <label>{t('Code d’accès', 'Access code')}<input type="password" autoComplete="off" value={code} maxLength={256} required disabled={exam.working} onChange={e => setCode(e.target.value)} /></label> | |
| <button className="exercise-item" disabled={exam.working}>{t('Accéder à l’examen', 'Open assessment')}</button> | |
| </form> : <> | |
| {exam.quizPending ? <p>{t('Commencez par le quiz. Les exercices s’ouvriront quand vous l’aurez terminé.', 'Start with the quiz. The exercises open once you finish it.')}</p> | |
| : exam.auth.exam.exercises.map(item => <button key={item.id} className="exercise-item" aria-pressed={exam.selected?.id === item.id} disabled={exam.working} onClick={() => exam.choose(item)}>{item.title[locale]}</button>)} | |
| {!exam.auth.submissionAvailable && <p className="exam-warning">{t('L’enseignant doit encore configurer l’envoi des copies.', 'The teacher still needs to configure submissions.')}</p>} | |
| {exam.activity.syncError && <p role="alert">{t('Journal non synchronisé. Une nouvelle tentative sera faite au retour de la connexion.', 'Activity log not synced. It will be retried when the connection returns.')}</p>} | |
| </>} | |
| {exam.notice && <p role="status">{exam.notice}</p>} | |
| {exam.storageError && <p role="alert">{t('Stockage indisponible : téléchargez votre fichier .c avant de fermer cette page.', 'Storage unavailable: download your .c file before closing this page.')}</p>} | |
| </section>; | |
| } | |
| // Shown in place of the editor until the student finishes the quiz; it cannot be reopened afterwards. | |
| export function ExamQuiz({ exam }) { | |
| const [confirming, setConfirming] = useState(false); | |
| const { t, quizAnswers: answers } = exam; | |
| const questions = exam.auth.exam.quiz; | |
| const missing = questions.filter(item => !answers[item.id]?.trim()).length; | |
| return <section className="exam-quiz" aria-label="Quiz"> | |
| <strong>{t(`Quiz — ${questions.length} questions`, `Quiz — ${questions.length} questions`)}</strong> | |
| <p>{t('Répondez aux questions puis cliquez sur « Terminer le quiz ». Vos réponses sont alors envoyées à l’enseignant et le quiz n’est plus accessible ; les exercices s’ouvrent ensuite.', 'Answer the questions, then click “Finish quiz”. Your answers are sent to the teacher and the quiz closes; the exercises open next.')}</p> | |
| <ol>{questions.map((item, index) => <li key={item.id} className={answers[item.id]?.trim() ? 'is-answered' : undefined}><fieldset disabled={exam.working}> | |
| <legend><span className="exam-quiz-number">{t(`Question ${index + 1}`, `Question ${index + 1}`)}</span>{item.question}</legend> | |
| {/* highlightC escapes the source; the only markup is its token spans, as in the editor. */} | |
| {item.code && <pre className="exam-quiz-code"><code dangerouslySetInnerHTML={{ __html: highlightC(item.code) }} /></pre>} | |
| <div className="exam-quiz-answer"> | |
| <span className="exam-quiz-answer-title" aria-hidden="true">{item.choices ? t('Choisissez une réponse', 'Choose one answer') : t('Votre réponse', 'Your answer')}</span> | |
| {item.choices ? item.choices.map(choice => <label key={choice}><input type="radio" name={`quiz-${item.id}`} checked={answers[item.id] === choice} onChange={() => exam.answer(item.id, choice)} /><span>{choice}</span></label>) | |
| : <textarea aria-label={item.question} value={answers[item.id] || ''} maxLength={2000} placeholder={t('Écrivez votre réponse ici', 'Type your answer here')} onChange={e => exam.answer(item.id, e.target.value)} />} | |
| </div> | |
| </fieldset></li>)}</ol> | |
| {!confirming ? <button type="button" disabled={exam.working} onClick={() => setConfirming(true)}>{t('Terminer le quiz', 'Finish quiz')}</button> | |
| : <div className="exam-quiz-confirm" role="group" aria-label={t('Confirmation', 'Confirmation')}> | |
| <p>{missing ? t(`${missing} question(s) sans réponse. `, `${missing} unanswered question(s). `) : ''}{t('Après confirmation, vous ne pourrez plus revenir au quiz.', 'Once confirmed, you cannot come back to the quiz.')}</p> | |
| <button type="button" disabled={exam.working} onClick={async () => { if (!await exam.finishQuiz()) setConfirming(false); }}>{exam.working ? t('Envoi…', 'Sending…') : t('Confirmer et envoyer', 'Confirm and send')}</button> | |
| <button type="button" disabled={exam.working} onClick={() => setConfirming(false)}>{t('Revenir au quiz', 'Back to the quiz')}</button> | |
| </div>} | |
| </section>; | |
| } | |
| export function ExamActions({ exam, source, busy }) { | |
| return <> | |
| <button disabled={!exam.selected || exam.working} onClick={exam.keep}>{exam.t('Conserver code', 'Keep code')}</button> | |
| <button disabled={!exam.selected || !source.trim() || busy || exam.working || exam.sent || !exam.auth?.submissionAvailable} onClick={exam.submit}>{exam.working ? exam.t('Veuillez patienter…', 'Please wait…') : exam.sent ? exam.t('Copie envoyée', 'Submitted') : exam.t('Envoyer', 'Submit')}</button> | |
| <button disabled={!exam.hasCopies || busy || exam.working || exam.allSent || !exam.auth?.submissionAvailable} onClick={exam.submitAll}>{exam.allSent ? exam.t('Tout envoyé', 'All submitted') : exam.t('Tout envoyer', 'Submit all')}</button> | |
| </>; | |
| } | |