Skip to content

Commit dc3c6a7

Browse files
committed
bug: correct ans display
1 parent 3da2034 commit dc3c6a7

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

frontend/src/pages/responses.jsx

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export default function AdminResponses() {
1919
const [round, setRound] = useState(1);
2020
const [status, setStatus] = useState("unmarked");
2121
const [loading, setLoading] = useState(true);
22+
const normalize = (v) => String(v ?? "").trim();
23+
2224

2325
const fetchQuestions = async () => {
2426
const res = await api.get("/admin/questions", {
@@ -209,35 +211,48 @@ export default function AdminResponses() {
209211
{user.mcqQuestions.map((q, i) => {
210212
const qid = String(q.id || q.uuid);
211213
const correctAnswer = q.options?.[Number(q.correctIndex)];
214+
212215
const userAnswer = user.answersMap?.[qid];
216+
const isCorrect =normalize(userAnswer) === normalize(correctAnswer);
217+
213218
if (userAnswer == null || userAnswer === "N/A") return null;
214219

215220
return (
216221
<div key={qid} className="bg-black/40 p-4 rounded-xl">
217222
<p className="text-neutral-400">Q{i + 1}</p>
218223
<p className="font-semibold mt-1">{q.question}</p>
219224

220-
{q.options.map((opt, optIdx) => (
221-
<p key={optIdx} className={`px-3 py-2 rounded-lg mt-2 ${
222-
opt === correctAnswer ? "bg-green-800" :
223-
opt === userAnswer ? "bg-red-800" :
225+
{q.options.map((opt, optIdx) => {
226+
const isUser = normalize(opt) === normalize(userAnswer);
227+
const isRight = normalize(opt) === normalize(correctAnswer); //had to normalize
224228

225-
"bg-neutral-800"
226-
}`}>
227-
{optIdx + 1}. {opt}
228-
</p>
229-
))}
229+
return (
230+
<p
231+
key={optIdx}
232+
className={`px-3 py-2 rounded-lg mt-2 ${
233+
isRight
234+
? "bg-green-500"
235+
: isUser
236+
? "bg-red-500"
237+
: "bg-neutral-800"
238+
}`}
239+
>
240+
{optIdx + 1}. {opt}
241+
</p>
242+
);
243+
})}
230244

245+
246+
231247
<p className="mt-3 text-green-400">
232248
Correct : {correctAnswer ?? "N/A"}
233249
</p>
234-
<p className={`mt-1 ${
235-
userAnswer === correctAnswer ? "text-green-400" : "text-red-400"
236-
237-
}`}>
238-
User : {userAnswer ?? "N/A"}
250+
<p className={`mt-1 ${isCorrect ? "text-green-400" : "text-red-400"}`}>
251+
User : {userAnswer ?? "N/A"}
252+
239253
</p>
240254
</div>
255+
241256
);
242257
})}
243258

0 commit comments

Comments
 (0)