Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | 104x 4x 96x 96x 96x 96x 96x 96x 96x 30x 3x 3x 3x 3x 27x 24x 24x 24x 24x 3x 3x 3x 3x 96x 4x 41x 41x 41x 10x 10x 41x 8x 8x 41x 1x 1x 41x 4x 4x 2x 41x 30x 12x 11x 4x 32x 32x 32x 6x 6x 32x 32x 32x 6x 16x 2x 4x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 52x 32x 96x 52x 52x 52x 52x 48x 48x 48x 48x 52x | /**
* Modified by Allan Ninal — 2026-08-12
*
* The points-override editor now validates through parsePointsDraft, mirroring the
* API's 0-1000 bound and rejecting Infinity ("1e999") which the old NaN-only check
* let through as a JSON null.
*/
import React, { useEffect, useState } from "react";
import {
Box,
Button,
Paper,
Typography,
Divider,
Chip,
IconButton,
TextField,
CircularProgress,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
} from "@mui/material";
import { useTheme, alpha } from "@mui/material/styles";
import CheckCircleIcon from "@mui/icons-material/CheckCircle";
import CheckCircleOutlineIcon from "@mui/icons-material/CheckCircleOutline";
import CancelOutlinedIcon from "@mui/icons-material/CancelOutlined";
import EditIcon from "@mui/icons-material/Edit";
import CheckIcon from "@mui/icons-material/Check";
import CloseIcon from "@mui/icons-material/Close";
import HourglassEmptyIcon from "@mui/icons-material/HourglassEmpty";
import MathContent from "@/utils/components/MathContent";
import ReadOnlyMathEditor from "@/utils/components/TinyMCETextEditorReadOnly";
import { questionCardSurfaceBg } from "@/utils/components/question-bank/question-display/utils/questionCardStyles";
import { getPrimaryAnswerContent } from "@/utils/components/question-bank/question-display/utils/questionAnswerUtils";
import {
extractContent,
getCorrectAnswerText,
getGivenAnswerText,
getQuestionTypeLabel,
isChoiceInAnswer,
MAX_QUESTION_POINTS,
parsePointsDraft,
stripHtml,
} from "./submissionAnswerUtils";
import BlankAnswerQuestion, { buildBlankSpan } from "./BlankAnswerQuestion";
import SubmissionGraphAnswer, { SubmissionGraphReview } from "./SubmissionGraphAnswer";
import { SubmissionInteractiveDotsReview } from "./SubmissionInteractiveDotsAnswer";
import {
isInteractiveDotsQuestionType,
normalizeQuestionType,
} from "@/utils/components/question-bank/question-display/interactive-dots/interactiveDotsUtils";
const letters = Array.from({ length: 26 }, (_, i) => String.fromCharCode(65 + i));
const ChoiceRow = ({ letter, content, isCorrect, isSelected }) => {
const theme = useTheme();
const dark = theme.palette.mode === "dark";
let borderColor = alpha(theme.palette.grey[500], dark ? 0.28 : 0.18);
let bgColor = dark ? "#2c2f34" : "#f6f7f8";
let badgeColor = alpha(theme.palette.grey[500], dark ? 0.2 : 0.12);
let badgeTextColor = theme.palette.text.secondary;
// Only the option the student actually picked gets highlighted — green if
// it happens to be correct, red if not. The correct answer (when different
// from what was picked) is surfaced separately in the "Correct Answer" panel.
// isCorrect is null when the backend withheld grading data (correctAnswer
// not included) — that's "unknown", not "wrong", so it gets a neutral
// selected look instead of red.
if (isSelected) {
if (isCorrect === null) {
borderColor = alpha(theme.palette.info.main, 0.45);
bgColor = dark ? "#1e2a38" : "#eef4fb";
badgeColor = theme.palette.info.main;
badgeTextColor = theme.palette.info.contrastText;
} else if (isCorrect) {
borderColor = alpha(theme.palette.success.main, 0.45);
bgColor = dark ? "#1a352c" : "#edf7f0";
badgeColor = theme.palette.success.main;
badgeTextColor = theme.palette.success.contrastText;
} else {
borderColor = alpha(theme.palette.error.main, 0.45);
bgColor = dark ? "#3a1f1f" : "#fdecea";
badgeColor = theme.palette.error.main;
badgeTextColor = theme.palette.error.contrastText;
}
}
return (
<Paper
elevation={0}
sx={{
display: "flex",
alignItems: "center",
minHeight: 40,
py: 0.75,
px: 1.25,
borderRadius: 1.25,
border: "1px solid",
borderColor,
bgcolor: bgColor,
boxShadow: "none",
}}
>
<Box
sx={{
width: 24,
height: 24,
borderRadius: "50%",
flexShrink: 0,
bgcolor: badgeColor,
color: badgeTextColor,
display: "flex",
alignItems: "center",
justifyContent: "center",
fontWeight: 600,
fontSize: theme.typography.pxToRem(12.5),
mr: 1,
}}
>
{letter}
</Box>
<Typography
variant="body2"
component="div"
sx={{ width: "100%", flex: 1, minWidth: 0, color: "text.primary" }}
>
<MathContent content={content} backgroundColor={bgColor} />
</Typography>
{isSelected &&
isCorrect !== null &&
(isCorrect ? (
<CheckCircleIcon fontSize="small" sx={{ ml: 1, flexShrink: 0, color: "success.main" }} />
) : (
<CancelOutlinedIcon fontSize="small" sx={{ ml: 1, flexShrink: 0, color: "error.main" }} />
))}
</Paper>
);
};
/**
* Inline points editor swapped in for the read-only points Chip when
* `editablePoints` is set. Edits are scoped to THIS assignment's question
* points override (assignments_collection) — the shared question bank
* document is never touched by the save handler this calls into.
*/
const PointsEditor = ({ points, isSaving, onSave }) => {
const [isEditing, setIsEditing] = useState(false);
const [draft, setDraft] = useState(points ?? "");
// Once the parent confirms the save (points prop actually changes), close
// the editor — mirrors CommentBox's pattern for its `comment` prop so a
// successful save doesn't leave the field sitting open.
useEffect(() => {
setDraft(points ?? "");
setIsEditing(false);
}, [points]);
const startEditing = () => {
setDraft(points ?? "");
setIsEditing(true);
};
const cancelEditing = () => {
setDraft(points ?? "");
setIsEditing(false);
};
const save = () => {
// Mirrors the API's own 0-1000 bound; also rejects Infinity, which a
// NaN-only check let through ("1e999" in a number field).
const parsed = parsePointsDraft(draft);
if (parsed === null) return;
onSave(parsed);
};
if (isEditing) {
return (
<Box sx={{ display: "flex", alignItems: "center", gap: 0.5 }}>
<TextField
autoFocus
type="number"
size="small"
variant="outlined"
value={draft}
disabled={isSaving}
onChange={(e) => setDraft(e.target.value)}
inputProps={{
min: 0,
max: MAX_QUESTION_POINTS,
step: 0.5,
style: { padding: "4px 8px", width: 56 },
}}
/>
<IconButton size="small" color="primary" onClick={save} disabled={isSaving} aria-label="Save points">
{isSaving ? <CircularProgress size={16} /> : <CheckIcon fontSize="small" />}
</IconButton>
<IconButton size="small" onClick={cancelEditing} disabled={isSaving} aria-label="Cancel">
<CloseIcon fontSize="small" />
</IconButton>
</Box>
);
}
return (
<Box sx={{ display: "flex", alignItems: "center", gap: 0.25 }}>
{points !== undefined && points !== null && (
<Chip label={`${points} ${Number(points) === 1 ? "pt" : "pts"}`} size="small" variant="outlined" />
)}
<IconButton size="small" onClick={startEditing} aria-label="Edit points">
<EditIcon sx={{ fontSize: 16 }} />
</IconButton>
</Box>
);
};
/**
* Marking control for one written answer.
*
* Separate from PointsEditor on purpose, because they do different things. PointsEditor
* changes what a question is WORTH, for every student in the assignment. This awards
* what ONE student earned for their own answer, and leaves the rest of the class alone.
*
* Points out of the question's own total rather than a correct/incorrect toggle:
* written work is usually part right, and partial credit is the reason it is marked by
* a person at all.
*/
const MarkEditor = ({ maxPoints, awarded, feedback, isSaving, onSave }) => {
const [points, setPoints] = useState(awarded ?? "");
const [note, setNote] = useState(feedback ?? "");
// Reopen against whatever the parent last confirmed — mirrors PointsEditor, so a
// save that lands does not leave the fields showing the previous mark.
useEffect(() => {
setPoints(awarded ?? "");
setNote(feedback ?? "");
}, [awarded, feedback]);
const parsed = parsePointsDraft(points);
const withinQuestion = parsed !== null && parsed >= 0 && parsed <= maxPoints;
return (
<Box sx={{ mt: 1.5 }}>
<Divider sx={{ mb: 1.5 }} />
<Box sx={{ display: "flex", alignItems: "center", gap: 1, flexWrap: "wrap" }}>
<Typography variant="subtitle2" fontWeight={600}>
Mark this answer
</Typography>
<TextField
type="number"
size="small"
label="Points"
value={points}
disabled={isSaving}
onChange={(event) => setPoints(event.target.value)}
inputProps={{ min: 0, max: maxPoints, step: 0.5, "aria-label": "Points awarded" }}
sx={{ width: 110 }}
/>
<Typography variant="body2" color="text.secondary">
out of {maxPoints}
</Typography>
</Box>
<TextField
fullWidth
multiline
minRows={2}
size="small"
label="Feedback for the student (optional)"
value={note}
disabled={isSaving}
onChange={(event) => setNote(event.target.value)}
sx={{ mt: 1.5 }}
/>
<Box sx={{ display: "flex", alignItems: "center", gap: 1, mt: 1 }}>
<Button
variant="contained"
size="small"
// Disabled rather than clamped. Silently turning 40 into 5 would tell
// the teacher their mark was accepted as typed when it was not.
disabled={isSaving || !withinQuestion}
onClick={() => onSave(parsed, note)}
>
{isSaving ? <CircularProgress size={16} /> : "Save mark"}
</Button>
{!withinQuestion && points !== "" && (
<Typography variant="caption" color="error">
Award between 0 and {maxPoints}.
</Typography>
)}
</Box>
</Box>
);
};
/**
* Single-question card showing a submitted answer: the question stem, the
* student's answer highlighted/rendered by type, and the correct answer.
* Shared by the teacher's "Individual Answers" analytics tab (viewing an
* arbitrary student) and the student's own "My Submission" page — same
* `question` (from a submission-fetch response's `details[]`) and
* `answerEntry` (from that response's `studentAnswers[]`) shape either way.
*
* `editablePoints` (teacher only) swaps the static points Chip for an inline
* editor; `onPointsSave(points)` persists the edit via the assignment's
* per-question points-override endpoint.
*/
const SubmissionQuestionCard = ({
question,
answerEntry,
itemNumber,
settings,
editablePoints = false,
isSavingPoints = false,
onPointsSave,
canMark = false,
isSavingMark = false,
onMarkSave,
}) => {
const theme = useTheme();
const cardBg = questionCardSurfaceBg(theme);
const rawAnswer = answerEntry?.answer;
// The backend omits isCorrect/correctAnswer entirely whenever it isn't allowed
// to reveal them yet (assignment has "show correct answers" disabled, OR the
// submission is still in-progress / pending late-submission review) — that's
// "ungraded/unknown", not "wrong", so it must not collapse to false via ??.
// Presence in the payload is the ground truth for what's safe to render;
// `settings` (only sent by the student submission-fetch endpoint) is used
// purely to tell "teacher disabled this" apart from "not gradable yet" so we
// can explain the missing indicator instead of just omitting it silently.
// A written answer the auto-grader could not confirm is HELD, not wrong. The
// backend sends isCorrect as null for these and adds needsMarking, and sends
// needsMarking whether or not the assignment reveals answers — so the student can
// be told their work is waiting for a person rather than shown a verdict nobody
// has reached.
const awaitingMarking = answerEntry?.needsMarking === true;
const hasGradingData = answerEntry?.isCorrect !== undefined && answerEntry?.isCorrect !== null;
const isCorrect = hasGradingData ? answerEntry.isCorrect : null;
const hasAnswer = answerEntry !== undefined && answerEntry !== null;
const hasCorrectAnswerData = question?.correctAnswer !== undefined && question?.correctAnswer !== null;
const correctAnswersDisabledByTeacher = settings?.show_correct_answers_after_submit === false;
const correctAnswerText = getCorrectAnswerText(question);
const givenAnswerText = getGivenAnswerText(question, rawAnswer);
const isBlankType = ["drag-and-drop", "drop-down-menu"].includes(question?.questionType);
const isChoiceType = ["multiple-choice", "checkbox"].includes(question?.questionType);
const isGmsType = isInteractiveDotsQuestionType(question?.questionType);
const isGraphType = normalizeQuestionType(question?.questionType) === "graph" && !isGmsType;
const isMultiGroupType = ["single-stimulus", "multi-part-question"].includes(question?.questionType);
const isGridType = question?.questionType === "grid-question";
const renderChoiceList = () => (
<Box sx={{ display: "flex", flexDirection: "column", gap: 0.75, mt: 1 }}>
{(question.choices || []).map((choice, index) => (
<ChoiceRow
key={index}
letter={letters[index]}
content={choice.text}
isCorrect={
hasCorrectAnswerData ? isChoiceInAnswer(question?.correctAnswer?.content, choice.text) : null
}
isSelected={isChoiceInAnswer(rawAnswer, choice.text)}
/>
))}
</Box>
);
// Grid Question's answer is [{id: row id, answer: chosen column TEXT}] —
// the same {id, answer} shape drag-and-drop uses, but rendered as a
// rows × columns table (like the teacher-facing GridQuestionViewOnly)
// instead of inline blanks, since a grid's rows have no stem position to
// substitute into.
const renderGridList = () => {
const rows = question?.rows || [];
const gridChoices = question?.choices || [];
const studentAnswers = Array.isArray(rawAnswer) ? rawAnswer : [];
const correctAnswers = Array.isArray(question?.correctAnswer?.content) ? question.correctAnswer.content : [];
return (
<TableContainer
component={Paper}
variant="outlined"
sx={{ mt: 1, borderColor: alpha(theme.palette.grey[500], theme.palette.mode === "dark" ? 0.28 : 0.18) }}
>
<Table size="small">
<TableHead>
<TableRow>
<TableCell />
{gridChoices.map((column) => (
<TableCell key={column.id} align="center" sx={{ fontWeight: 600 }}>
{stripHtml(extractContent(column.text))}
</TableCell>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.map((row) => {
const selectedText = studentAnswers.find((a) => a?.id === row.id)?.answer;
const correctText = hasCorrectAnswerData
? correctAnswers.find((a) => a?.id === row.id)?.answer
: undefined;
return (
<TableRow key={row.id}>
<TableCell>{stripHtml(extractContent(row.text))}</TableCell>
{gridChoices.map((column) => {
const isSelected = selectedText === column.text;
const isCorrectColumn = hasCorrectAnswerData && correctText === column.text;
let icon = null;
if (isSelected && hasCorrectAnswerData) {
icon = isCorrectColumn ? (
<CheckCircleIcon fontSize="small" sx={{ color: "success.main" }} />
) : (
<CancelOutlinedIcon fontSize="small" sx={{ color: "error.main" }} />
);
} else if (isSelected) {
icon = <CheckCircleOutlineIcon fontSize="small" color="action" />;
} else if (isCorrectColumn) {
icon = <CheckCircleIcon fontSize="small" sx={{ color: "success.main" }} />;
}
return (
<TableCell
key={column.id}
align="center"
sx={{
bgcolor: isCorrectColumn
? alpha(theme.palette.success.main, 0.12)
: isSelected
? alpha(theme.palette.grey[500], 0.08)
: undefined,
}}
>
{icon}
</TableCell>
);
})}
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
);
};
// Single-Stimulus stores ONE combined answer for the whole question,
// shaped `{ [group_id]: <that group's own answer> }` (see SingleStimulus.jsx
// and answer_checking.py's grade_single_stimulus_answer) — each group is
// its own independently-graded mini-question, so it gets its own header
// (type/points/correct-incorrect) and its own choice list rather than folding
// into the single-answer panels below.
// A "drop-down"/"drag-and-drop" group's own content, with its `__blank__`
// markers replaced by the student's answer at each blank (colored by
// correctness) — the group-scoped counterpart of BlankAnswerQuestion,
// since a group's own `content`/`choices`/`correctAnswer.answers` field
// names and nested choices shape don't match the top-level
// BlankAnswerQuestion question's `question`/flat-choices/
// `correctAnswer.content` shape. Blank identity differs by type, mirroring
// BlankAnswerQuestion's own top-level dropDown/dragAndDrop split: a
// "drop-down" group keys each blank by that position's own Select id
// (choices[idx].id); a "drag-and-drop" group keys each blank by its
// 0-based position directly (its choices are ONE shared pool, not
// per-blank).
const buildGroupBlankHtml = (group, studentAnswer, hasGroupCorrectAnswerData) => {
const correctAnswers = group?.correctAnswer?.answers;
const answerList = Array.isArray(studentAnswer) ? studentAnswer : [];
const isDropDownGroup = group?.type === "drop-down";
let blankIndex = 0;
return (group?.content || "").replace(/__blank__/g, () => {
const idx = blankIndex++;
const blankId = isDropDownGroup ? (group?.choices?.[idx]?.id ?? idx) : idx;
const studentEntry = answerList.find((b) => b?.id === blankId);
const studentRaw = extractContent(studentEntry?.answer);
const correctRaw = extractContent(correctAnswers?.[idx]);
return buildBlankSpan(studentRaw, correctRaw, theme, hasGroupCorrectAnswerData);
});
};
const renderGroupsList = () => {
const groups = question?.groups || [];
const answerByGroup = rawAnswer && typeof rawAnswer === "object" ? rawAnswer : {};
const groupResults = answerEntry?.groupResults || {};
return (
<Box sx={{ display: "flex", flexDirection: "column", gap: 2.5, mt: 1 }}>
{groups.map((group, groupIndex) => {
const groupAnswer = answerByGroup[group.group_id];
const groupResult = groupResults[group.group_id];
const hasGroupResult = groupResult !== undefined && groupResult !== null;
return (
<Box key={group.group_id ?? groupIndex}>
<Box
sx={{
display: "flex",
alignItems: "center",
gap: 1,
mb: 0.75,
flexWrap: "wrap",
}}
>
<Typography variant="subtitle2" fontWeight={600}>
Group {groupIndex + 1}
</Typography>
<Chip label={getQuestionTypeLabel(group.type)} size="small" variant="outlined" />
{group.points !== undefined && group.points !== null && (
<Chip
label={`${group.points} ${Number(group.points) === 1 ? "pt" : "pts"}`}
size="small"
variant="outlined"
/>
)}
{hasGroupResult && (
<Chip
icon={
groupResult.isCorrect ? <CheckCircleOutlineIcon /> : <CancelOutlinedIcon />
}
label={
groupResult.isCorrect
? "Correct"
: `${groupResult.earnedPoints ?? 0}/${groupResult.maxPoints ?? group.points ?? 0} pts`
}
size="small"
color={groupResult.isCorrect ? "success" : "error"}
/>
)}
</Box>
{group.questionText && (
<Box sx={{ mb: 1 }}>
<ReadOnlyMathEditor content={group.questionText} backgroundColor={cardBg} />
</Box>
)}
{(group.type === "multiple-choice" || group.type === "checkbox") && (
<Box sx={{ display: "flex", flexDirection: "column", gap: 0.75 }}>
{(group.choices || []).map((choice, choiceIndex) => (
<ChoiceRow
key={choice.id ?? choiceIndex}
letter={letters[choiceIndex]}
content={choice.text}
isCorrect={
hasCorrectAnswerData
? isChoiceInAnswer(group?.correctAnswer?.answers, choice.text)
: null
}
isSelected={isChoiceInAnswer(groupAnswer, choice.text)}
/>
))}
</Box>
)}
{group.type === "free-response" && (
<Box sx={{ display: "flex", flexDirection: "column", gap: 1 }}>
{renderAnswerPanel(
"Student's Answer",
typeof groupAnswer === "string" && groupAnswer.trim()
? groupAnswer
: "No answer",
hasGroupResult ? (groupResult.isCorrect ? "success" : "error") : "default"
)}
{hasCorrectAnswerData &&
renderAnswerPanel(
"Correct Answer",
getPrimaryAnswerContent(group?.correctAnswer?.answers) || "N/A",
"success"
)}
</Box>
)}
{group.type === "graph" && (
<Box sx={{ display: "flex", flexDirection: "column", gap: 1 }}>
<Box>
<Typography
variant="caption"
color="text.secondary"
sx={{ fontWeight: 600, display: "block", mb: 0.5 }}
>
Student's Answer
</Typography>
<SubmissionGraphAnswer content={groupAnswer} />
</Box>
{hasCorrectAnswerData && (
<Box>
<Typography
variant="caption"
color="text.secondary"
sx={{ fontWeight: 600, display: "block", mb: 0.5 }}
>
Correct Answer
</Typography>
<SubmissionGraphAnswer content={group?.correctAnswer?.answers} />
</Box>
)}
</Box>
)}
{(group.type === "drop-down" || group.type === "drag-and-drop") && (
<Box>
<Typography
variant="caption"
color="text.secondary"
sx={{ fontWeight: 600, display: "block", mb: 0.5 }}
>
Student's Answer
</Typography>
<ReadOnlyMathEditor
content={buildGroupBlankHtml(group, groupAnswer, hasCorrectAnswerData)}
backgroundColor={cardBg}
/>
</Box>
)}
</Box>
);
})}
</Box>
);
};
const renderAnswerPanel = (label, text, variant) => {
const dark = theme.palette.mode === "dark";
const borderColor = variant === "success" ? "success.main" : variant === "error" ? "error.main" : "divider";
const bgcolor =
variant === "success"
? dark
? "#1a352c"
: "#edf7f0"
: variant === "error"
? dark
? "#3a1f1f"
: "#fdecea"
: "action.hover";
return (
<Box sx={{ mt: 1.5, p: 1.5, borderRadius: 1.5, border: "1px solid", borderColor, bgcolor }}>
<Typography
variant="caption"
color="text.secondary"
sx={{ fontWeight: 600, display: "block", mb: 0.5 }}
>
{label}
</Typography>
{/* free-response is the only type that can carry rich/math markup here
(see getGivenAnswerText/getCorrectAnswerText) — every other type's
text is a plain letter/short string, which renders identically
through ReadOnlyMathEditor as it would as plain text. */}
<ReadOnlyMathEditor content={text} backgroundColor={bgcolor} />
</Box>
);
};
return (
<Paper elevation={0} variant="outlined" sx={{ p: 3, borderRadius: 2, borderColor: theme.palette.divider }}>
<Box
sx={{
display: "flex",
justifyContent: "space-between",
alignItems: "center",
mb: 2,
gap: 1,
flexWrap: "wrap",
}}
>
<Box sx={{ display: "flex", alignItems: "center", gap: 1.5 }}>
<Typography variant="subtitle1" fontWeight={600}>
Question {itemNumber}
</Typography>
<Chip
label={getQuestionTypeLabel(question?.questionType)}
size="small"
variant="outlined"
color="primary"
/>
{editablePoints ? (
<PointsEditor points={question?.points} isSaving={isSavingPoints} onSave={onPointsSave} />
) : (
question?.points !== undefined &&
question?.points !== null && (
<Chip
label={`${question.points} ${Number(question.points) === 1 ? "pt" : "pts"}`}
size="small"
variant="outlined"
/>
)
)}
</Box>
{!hasAnswer ? (
<Chip label="Not answered" size="small" color="default" />
) : awaitingMarking ? (
<Chip
icon={<HourglassEmptyIcon />}
label="Awaiting marking"
size="small"
color="warning"
variant="outlined"
/>
) : hasGradingData ? (
<Chip
icon={isCorrect ? <CheckCircleOutlineIcon /> : <CancelOutlinedIcon />}
label={isCorrect ? "Correct" : "Incorrect"}
size="small"
color={isCorrect ? "success" : "error"}
/>
) : (
correctAnswersDisabledByTeacher && (
<Chip label="Grading hidden by teacher" size="small" color="default" variant="outlined" />
)
)}
</Box>
{isBlankType ? (
<Box sx={{ mb: 1.5 }}>
<BlankAnswerQuestion question={question} rawAnswer={rawAnswer} />
</Box>
) : (
<Box sx={{ mb: 1.5 }}>
<ReadOnlyMathEditor content={question?.question} backgroundColor={cardBg} />
</Box>
)}
{isChoiceType && renderChoiceList()}
{isMultiGroupType && renderGroupsList()}
{isGridType && renderGridList()}
{isGraphType && (
<SubmissionGraphReview
studentContent={rawAnswer}
correctContent={
hasCorrectAnswerData
? (question?.correctAnswer?.content ?? question?.correctAnswer?.answers)
: null
}
/>
)}
{isGmsType && (
<SubmissionInteractiveDotsReview
studentContent={rawAnswer}
correctContent={
hasCorrectAnswerData
? (question?.correctAnswer?.content ?? question?.correctAnswer?.answers)
: null
}
/>
)}
{!isBlankType &&
!isChoiceType &&
!isGraphType &&
!isGmsType &&
!isMultiGroupType &&
!isGridType &&
renderAnswerPanel(
"Student's Answer",
givenAnswerText,
!hasAnswer || !hasGradingData ? "default" : isCorrect ? "success" : "error"
)}
{/* Single-Stimulus shows its correct answer per group above (renderGroupsList),
and Grid Question marks its correct column inline (renderGridList) — the
combined summary in correctAnswerText would be redundant for either.
Graph Multiple-Select renders both canvases above. */}
{hasCorrectAnswerData && !isMultiGroupType && !isGridType && !isGmsType && !isGraphType && (
<>
<Divider sx={{ my: 1.5 }} />
{renderAnswerPanel("Correct Answer", correctAnswerText || "N/A", "success")}
</>
)}
{/* The teacher's own note travels with the mark, so the student learns why
they got the marks rather than only how many. */}
{answerEntry?.markFeedback && (
<>
<Divider sx={{ my: 1.5 }} />
{renderAnswerPanel("Teacher's feedback", answerEntry.markFeedback, "default")}
</>
)}
{canMark && (
<MarkEditor
maxPoints={question?.points ?? 0}
awarded={answerEntry?.earnedPoints}
feedback={answerEntry?.markFeedback}
isSaving={isSavingMark}
onSave={onMarkSave}
/>
)}
</Paper>
);
};
export default SubmissionQuestionCard;
|