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 | import React, { useState } from "react";
import { Typography, Paper, Box, Stack, Chip, Divider, IconButton } from "@mui/material";
import SoftChip from "@/utils/components/feature-access/SoftChip";
import { HtmlTooltip } from "@/utils/components/question-bank/utils";
import { utcToLocalTimeZone } from "@/utils/helpers/utcToLocalTime";
import { useTheme } from "@mui/material/styles";
import { createGraphInstance } from "@/lib/graph2d/graphInstanceHelper";
import ReadOnlyMathEditor from "@/utils/components/TinyMCETextEditorReadOnly";
import HelpIcon from "@mui/icons-material/Help";
import CalendarTodayIcon from "@mui/icons-material/CalendarToday";
import CategoryIcon from "@mui/icons-material/Category";
import QuestionDisplayRenderer from "@/utils/components/question-bank/question-display/utils/QuestionDisplayRenderer";
import { needsSharedGraphCanvas } from "@/utils/components/question-bank/question-display/interactive-dots/interactiveDotsUtils";
import {
correctAnswerSurfaceBg,
questionCardSurfaceBg,
} from "@/utils/components/question-bank/question-display/utils/questionCardStyles";
/** Mirrors the question-bank's card chrome exactly (QuestionBank.jsx: tinted
header bar with an info tooltip + points + item counter, hover lift, and a
plain primary-chip tags footer) so a question looks the same whether it's
being browsed in the bank or reviewed on an assignment. The edit/delete
menu and read-aloud button from the bank's card are left out — this is a
read-only review context, not question management. */
const QuestionCard = ({ question, itemNumber, total, children, idPrefix }) => {
const theme = useTheme();
const cardBg = questionCardSurfaceBg(theme);
const hasTags =
question.createdDate ||
question.assignmentType ||
question.questionType ||
question.category ||
question.difficulty ||
question.teksCode;
return (
<Paper
id={idPrefix ? `${idPrefix}-question-${itemNumber}` : undefined}
elevation={2}
sx={{
border: `1px solid ${theme.palette.divider}`,
borderRadius: 3,
overflow: "hidden",
transition: theme.transitions.create(["box-shadow", "transform", "border-color"], {
duration: theme.transitions.duration.short,
}),
"&:hover": {
boxShadow: theme.shadows[8],
borderColor: "primary.main",
transform: "translateY(-3px)",
},
}}
>
{/* Card header */}
<Box
sx={{
px: 2,
py: 1.25,
display: "flex",
alignItems: "center",
justifyContent: "space-between",
flexWrap: "wrap",
gap: 1,
borderBottom: `1px solid ${theme.palette.divider}`,
}}
>
<Box sx={{ display: "flex", alignItems: "center", gap: 0.5 }}>
<HtmlTooltip
title={
<Box sx={{ display: "flex", flexDirection: "column", gap: 0.25 }}>
<span>Category: {question.assignmentType}</span>
<span>Type: {question.questionType}</span>
<span>Points: {question.points}</span>
<span>Difficulty: {question.difficulty}</span>
<span>TEKS Code: {question.teksCode}</span>
{question.createdDate && (
<span>Date Created: {utcToLocalTimeZone(question.createdDate)}</span>
)}
</Box>
}
>
<IconButton size="small">
<HelpIcon fontSize="small" />
</IconButton>
</HtmlTooltip>
<Typography variant="body2" fontWeight={600}>
{question.points || 1} pts
</Typography>
</Box>
{total ? (
<Typography variant="caption" color="text.secondary">
{itemNumber} of {total}
</Typography>
) : null}
<div></div>
</Box>
{/* Question body */}
<Box sx={{ p: "1rem 1.5rem", wordBreak: "break-word", overflowWrap: "anywhere" }}>
{children}
{/* Question Details */}
{question.questionDetails && (
<Box
sx={{
mt: 2,
p: 2,
backgroundColor: theme.palette.grey[50],
borderRadius: 1,
borderLeft: `3px solid ${theme.palette.info.main}`,
}}
>
<Typography
variant="caption"
color="text.secondary"
sx={{ fontWeight: 600, mb: 0.5, display: "block" }}
>
Question Details
</Typography>
<Typography variant="body2" color="text.secondary" component="div">
<ReadOnlyMathEditor content={question.questionDetails} backgroundColor={cardBg} />
</Typography>
</Box>
)}
{/* Answer Details */}
{question.correctAnswer?.answerDetails && (
<Box
sx={{
mt: 2,
p: 2,
backgroundColor: theme.palette.success.lighter || "#e8f5e9",
borderRadius: 1,
borderLeft: `3px solid ${theme.palette.success.main}`,
}}
>
<Typography
variant="caption"
color="text.secondary"
sx={{ fontWeight: 600, mb: 0.5, display: "block" }}
>
Answer Explanation
</Typography>
<Typography variant="body2" color="text.secondary" component="div">
<ReadOnlyMathEditor
content={question.correctAnswer.answerDetails}
backgroundColor={correctAnswerSurfaceBg(theme)}
/>
</Typography>
</Box>
)}
</Box>
{/* Tags footer */}
{hasTags && (
<React.Fragment>
<Divider />
<Box sx={{ display: "flex", flexWrap: "wrap", gap: 0.75, px: 2, py: 1.25 }}>
{question.createdDate && (
<Chip size="small" color="primary" label={utcToLocalTimeZone(question.createdDate)} />
)}
{question.assignmentType && (
<Chip size="small" color="primary" label={question.assignmentType} />
)}
{question.questionType && <Chip size="small" color="primary" label={question.questionType} />}
{question.category && <Chip size="small" color="primary" label={question.category} />}
{question.difficulty && <Chip size="small" color="primary" label={question.difficulty} />}
{question.teksCode && <Chip size="small" color="primary" label={question.teksCode} />}
</Box>
</React.Fragment>
)}
</Paper>
);
};
const QuestionsList = ({ assignmentData, idPrefix, showHeader = true }) => {
const isShowAnswers = true;
let graphId = 0;
const [graphInstance] = useState(() => createGraphInstance());
// Support both data structures:
// 1. view-assignment: assignmentData.details, assignmentData.questions
// 2. new-assignment preview: assignmentData.step1, assignmentData.step2.selectedQuestions
const isPreviewMode = !!assignmentData?.step1 || !!assignmentData?.step2;
const title = isPreviewMode ? assignmentData?.step1?.title : assignmentData?.details?.title;
const description = isPreviewMode ? assignmentData?.step1?.description : assignmentData?.details?.description;
const assignmentType = isPreviewMode ? assignmentData?.step1?.type : assignmentData?.details?.type;
const semester = isPreviewMode ? assignmentData?.step1?.semester : assignmentData?.details?.semester;
const questions = isPreviewMode ? assignmentData?.step2?.selectedQuestions || [] : assignmentData?.questions || [];
const totalPoints = questions.reduce((sum, q) => sum + (q.points || 1), 0);
// No itemNumber passed through — mirrors QuestionBank.jsx, which relies on
// the card header's "N of total" counter instead of a second number
// repeated inside the question body.
const displayQuestion = (question) => {
const currentGraphId = needsSharedGraphCanvas(question) ? graphId++ : undefined;
return (
<QuestionDisplayRenderer
question={question}
showAnswers={isShowAnswers}
graphId={currentGraphId}
graphInstance={graphInstance}
/>
);
};
return (
<Box>
{/* Assignment Header — the new-assignment review step (Step4.jsx) has no
page-level header of its own, so it needs this. The view-assignment
pages (ViewAssignmentPage.jsx et al.) already render title/description/
type in their own header card above this component, so they opt out
with showHeader={false} rather than showing the same title twice. */}
{showHeader && (
<Box
sx={{
p: 1,
}}
>
<Typography variant="h5" sx={{ fontWeight: 600, mb: 1 }}>
{title || "Untitled Assignment"}
</Typography>
{description && (
<Typography variant="body2" sx={{ opacity: 0.9, mb: 2 }}>
{description}
</Typography>
)}
<Stack direction="row" flexWrap="wrap" gap={0.75} sx={{ mt: 2 }}>
{assignmentType ? (
<SoftChip
icon={<CategoryIcon sx={{ fontSize: 16 }} />}
label={assignmentType}
color="accent"
size="sm"
/>
) : null}
{semester ? (
<SoftChip
icon={<CalendarTodayIcon sx={{ fontSize: 16 }} />}
label={semester}
color="default"
size="sm"
/>
) : null}
</Stack>
</Box>
)}
{/* Questions List */}
<Box sx={{ p: 1 }}>
<Stack spacing={3}>
{questions.map((question, index) => (
<QuestionCard
key={question._id || index}
question={question}
itemNumber={index + 1}
total={questions.length}
idPrefix={idPrefix}
>
{displayQuestion(question)}
</QuestionCard>
))}
</Stack>
{questions.length === 0 && (
<Box sx={{ textAlign: "center", py: 6 }}>
<Typography variant="body1" color="text.secondary">
No questions in this assignment.
</Typography>
</Box>
)}
</Box>
</Box>
);
};
export default QuestionsList;
|