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 | 56x 56x 1x 43x 43x 43x 43x 43x 43x 43x 43x 43x 43x 2x 2x 2x 2x 43x 2x 43x 183x 183x 149x 34x 68x 260x 183x 43x 56x 56x 43x 31x 30x 2x 2x 4x 3x 3x 3x 3x 30x 43x 56x 2x 2x 2x | import React, { useState } from "react";
import "./SelectedQuestions.scss";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import { Button, Chip, Divider, IconButton, Paper, styled } from "@mui/material";
import VolumeUpIcon from "@mui/icons-material/VolumeUp";
import PlaylistAddIcon from "@mui/icons-material/PlaylistAdd";
import SearchOffIcon from "@mui/icons-material/SearchOff";
import ReadAloud from "@/utils/components/ReadAloud";
import { useDispatch } from "react-redux";
import SearchField from "@/utils/components/SearchField";
import { QuestionDisplayRenderer } from "@/utils/components/question-bank/question-display/utils";
import {
isInteractiveDotsQuestion,
needsSharedGraphCanvas,
} from "@/utils/components/question-bank/question-display/interactive-dots/interactiveDotsUtils";
import {
_deleteQuestion,
_teacherDeletePersonalQuestion,
_teacherFetchPersonalQuestions,
} from "@/store/slices/teacher/TeacherQuestionBank";
import { useSnackbar } from "notistack";
import HelpIcon from "@mui/icons-material/Help";
import Tooltip, { tooltipClasses } from "@mui/material/Tooltip";
import { useNavigate } from "react-router-dom";
import { useEffect } from "react";
import { Graph2D } from "graph2d-react";
import { createGraphInstance } from "@/lib/graph2d/graphInstanceHelper";
import { useTheme } from "@mui/material/styles";
import { utcToLocalTimeZone } from "@/utils/helpers/utcToLocalTime";
import AddIcon from "@mui/icons-material/Add";
import { useSelector } from "react-redux";
const HtmlTooltip = styled(({ className, ...props }) => <Tooltip {...props} classes={{ popper: className }} />)(
({ theme }) => ({
[`& .${tooltipClasses.tooltip}`]: {
backgroundColor: theme.palette.background.paper,
color: theme.palette.text.primary,
maxWidth: 220,
fontSize: theme.typography.pxToRem(12),
border: `1px solid ${theme.palette.divider}`,
},
})
);
const QuestionCards = ({ selectedQuestions, removeQuestion, hideButtonRemove }) => {
let graphId = 0; //will be only use for generating graph components
//graph
const graphInstance = createGraphInstance();
const { speak, cancelSpeech, speaking } = ReadAloud();
const dispatch = useDispatch();
const navigate = useNavigate();
const { enqueueSnackbar } = useSnackbar();
const [search, setSearch] = useState("");
const [showAnswers, setShowAnswers] = useState(true);
const [itemClick, setItemClick] = useState(); // for speaking highlight
const handleSpeakClick = (question, questionId) => {
const modifiedString = question.question;
const modifiedText = modifiedString.replace(/blank/g, "");
setItemClick(questionId);
speak(modifiedText);
};
const EmptyState = ({ noQuestions }) => (
<Box sx={{ py: 8, width: "100%", display: "flex", flexDirection: "column", alignItems: "center", gap: 1.5 }}>
<Box
sx={{
width: 72,
height: 72,
borderRadius: "50%",
backgroundColor: "action.hover",
display: "flex",
alignItems: "center",
justifyContent: "center",
mb: 1,
}}
>
{noQuestions ? (
<PlaylistAddIcon sx={{ fontSize: 36, color: "text.disabled" }} />
) : (
<SearchOffIcon sx={{ fontSize: 36, color: "text.disabled" }} />
)}
</Box>
<Typography variant="h6" fontWeight={600} color="text.secondary">
{noQuestions ? "No questions added yet" : "No questions found"}
</Typography>
<Typography variant="body2" color="text.disabled" textAlign="center">
{noQuestions ? "Go to the Search tab to add questions to this assignment" : "Try adjusting your search"}
</Typography>
</Box>
);
const filterList = (entries, searchValue) => {
let results = [];
if (!searchValue) {
results = [...entries];
} else {
results = [
...entries.filter((entry) =>
["question", "correctAnswer", "assignmentType", "questionType", "teksCode"].some(
(key) => entry[key] && entry[key].toString().toLowerCase().includes(searchValue.toLowerCase())
)
),
];
}
return results;
};
// Delegates to the shared renderer (also used by SearchQuestions.jsx and
// QuestionsList.jsx) instead of a locally-maintained switch — that switch
// had no "Embedded-Multiple-Choice" case, so that question type silently
// rendered nothing here (its `default: break;` returned undefined) even
// though every other question-display surface in the app already knew
// how to show it.
const displayQuestionType = (question) => {
const currentGraphId = needsSharedGraphCanvas(question) ? graphId++ : undefined;
return (
<QuestionDisplayRenderer
question={question}
showAnswers={showAnswers}
graphId={currentGraphId}
graphInstance={graphInstance}
/>
);
};
// import graph answers after init
useEffect(() => {
if (!graphInstance) return;
const timer = setTimeout(() => {
var curGraphId = 0;
selectedQuestions.forEach((item) => {
if (!needsSharedGraphCanvas(item)) return;
Eif (!isInteractiveDotsQuestion(item)) {
try {
graphInstance.importAnswer(item.correctAnswer?.answers, curGraphId);
} catch (err) {
// Canvas may not be ready yet; NonEmptyGraph will handle it
}
}
curGraphId++;
});
}, 200);
return () => clearTimeout(timer);
}, [selectedQuestions]);
return (
<Box sx={{ display: "flex", gap: 10, padding: "0 2%" }}>
<Box sx={{ flex: 5, display: "flex", flexDirection: "column", mb: 10 }}>
<>
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "space-between",
marginBottom: 5,
mt: 4,
}}
>
<Box
sx={{
width: "100%",
display: "flex",
alignItems: "center",
justifyContent: "space-between",
}}
>
<Box>
<SearchField search={search} setSearch={setSearch} placeHolder="Search Question" />
</Box>
<Typography variant="body1">
Total Selected Questions ({filterList(selectedQuestions, search).length})
</Typography>
</Box>
</Box>
{selectedQuestions && filterList(selectedQuestions, search).length > 0 ? (
<Box className="teacher-question-bank-items">
{filterList(selectedQuestions, search).map((question, index) => (
<Box key={question._id + ""}>
<Paper elevation={1}>
<Box
sx={{
p: "1rem",
display: "flex",
alignItems: "center",
justifyContent: "space-between",
}}
>
<Box sx={{ display: "flex", alignItems: "center", gap: 0.5 }}>
<HtmlTooltip
title={
<Box sx={{ display: "flex", flexDirection: "column" }}>
<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>
<span>
Date Created: {utcToLocalTimeZone(question.createdDate)}
</span>
</Box>
}
>
<IconButton>
<HelpIcon />
</IconButton>
</HtmlTooltip>
<Typography>{question.points} Points</Typography>
</Box>
<Typography>
Question {index + 1} of {filterList(selectedQuestions, search).length}
</Typography>
<Box sx={{ display: "flex", gap: 2 }}>
<IconButton
size="small"
color={speaking && itemClick === question._id ? "primary" : "gray"}
onClick={() => {
handleSpeakClick(question, question._id);
}}
>
<VolumeUpIcon />
</IconButton>
</Box>
</Box>
<Divider />
<Box
sx={{
p: "1rem 2rem",
wordBreak: "break-word",
overflowWrap: "break-word",
overflow: "hidden",
}}
>
{displayQuestionType(question)}
</Box>
<Divider />
<Box
sx={{
display: "flex",
alignItems: "center",
justifyContent: "space-between",
}}
>
<Box sx={{ display: "flex", flexWrap: "wrap", gap: 1, p: "1rem" }}>
{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>
<Box sx={{ p: "1rem" }}>
{!hideButtonRemove && (
<Button
onClick={() => {
removeQuestion(question);
enqueueSnackbar("Question successfully removed", {
variant: "success",
});
}}
startIcon={<AddIcon />}
variant="contained"
color="error"
sx={{ minWidth: 120 }}
>
Remove
</Button>
)}
</Box>
</Box>
</Paper>
</Box>
))}
</Box>
) : (
<Box sx={{ mt: 5, mb: 20 }}>
<EmptyState noQuestions={selectedQuestions.length === 0} />
</Box>
)}
</>
</Box>
</Box>
);
};
export default QuestionCards;
|