Fix CBT history react-markdown crash, fix test deletion cascade, fix cbt theme, add 180 NEET questions
This commit is contained in:
@@ -5,7 +5,6 @@ import { Button } from "@/components/ui/button"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Clock, Flag, ChevronLeft, ChevronRight, Pause as PauseIcon, MoreVertical, Calculator as CalculatorIcon, FlaskConical, Edit3, XCircle, Play, Shield, AlertTriangle, Moon, Sun } from "lucide-react"
|
||||
import Image from "next/image"
|
||||
import { useTheme } from "next-themes"
|
||||
import { useCBTStore, QuestionStatus } from "@/store/cbtStore"
|
||||
import { useExamTimer } from "@/hooks/useExamTimer"
|
||||
import ReactMarkdown from "react-markdown"
|
||||
@@ -38,7 +37,29 @@ export default function CBTExamPage({ params }: { params: Promise<{ examId: stri
|
||||
const [showPeriodicTable, setShowPeriodicTable] = useState(false);
|
||||
const [isPaused, setIsPaused] = useState(false);
|
||||
const [showSubmitConfirm, setShowSubmitConfirm] = useState(false);
|
||||
const { theme, setTheme } = useTheme();
|
||||
const [localTheme, setLocalTheme] = useState<string>('light');
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== 'undefined') {
|
||||
if (document.documentElement.classList.contains('dark')) {
|
||||
setLocalTheme('dark');
|
||||
} else {
|
||||
setLocalTheme('light');
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleThemeToggle = () => {
|
||||
if (document.documentElement.classList.contains('dark')) {
|
||||
document.documentElement.classList.remove('dark');
|
||||
localStorage.setItem('theme', 'light');
|
||||
setLocalTheme('light');
|
||||
} else {
|
||||
document.documentElement.classList.add('dark');
|
||||
localStorage.setItem('theme', 'dark');
|
||||
setLocalTheme('dark');
|
||||
}
|
||||
};
|
||||
|
||||
// Anti-cheat state
|
||||
const [violationCount, setViolationCount] = useState(0);
|
||||
@@ -63,9 +84,6 @@ export default function CBTExamPage({ params }: { params: Promise<{ examId: stri
|
||||
resetExamState,
|
||||
status,
|
||||
attemptId,
|
||||
currentQuestionId,
|
||||
getQuestion,
|
||||
examState
|
||||
} = useCBTStore();
|
||||
|
||||
const { formattedTime, isTimedOut } = useExamTimer();
|
||||
@@ -243,8 +261,8 @@ export default function CBTExamPage({ params }: { params: Promise<{ examId: stri
|
||||
<p className="font-semibold">Preferred Theme</p>
|
||||
<p className="text-sm text-muted-foreground">Choose dark or light mode for the exam</p>
|
||||
</div>
|
||||
<Button variant="outline" size="icon" onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
|
||||
{theme === 'dark' ? <Sun className="h-5 w-5" /> : <Moon className="h-5 w-5" />}
|
||||
<Button variant="outline" size="icon" onClick={handleThemeToggle}>
|
||||
{localTheme === 'dark' ? <Sun className="h-5 w-5" /> : <Moon className="h-5 w-5" />}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -267,13 +285,13 @@ export default function CBTExamPage({ params }: { params: Promise<{ examId: stri
|
||||
onRetake={examType === 'DPS' ? () => {
|
||||
resetExamState();
|
||||
window.location.reload();
|
||||
} : undefined}
|
||||
} : () => {}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const currentQuestion = getQuestion(currentQuestionId)
|
||||
const currentState = currentQuestion ? examState?.answers[currentQuestion.id] : null
|
||||
const currentQuestion = questions[currentQuestionIndex];
|
||||
const currentState = currentQuestion ? answers[currentQuestion.id] : null
|
||||
|
||||
const handleOptionSelect = (qId: string, letter: string, type: string) => {
|
||||
if (type === 'Multiple_Choice') {
|
||||
@@ -281,7 +299,11 @@ export default function CBTExamPage({ params }: { params: Promise<{ examId: stri
|
||||
const selectedArray = currentSelected.split(',').filter(Boolean);
|
||||
if (selectedArray.includes(letter)) {
|
||||
const newArray = selectedArray.filter((l: string) => l !== letter).sort();
|
||||
selectAnswer(qId, newArray.length > 0 ? newArray.join(',') : null);
|
||||
if (newArray.length > 0) {
|
||||
selectAnswer(qId, newArray.join(','));
|
||||
} else {
|
||||
clearResponse(qId);
|
||||
}
|
||||
} else {
|
||||
selectedArray.push(letter);
|
||||
selectAnswer(qId, selectedArray.sort().join(','));
|
||||
@@ -291,7 +313,8 @@ export default function CBTExamPage({ params }: { params: Promise<{ examId: stri
|
||||
}
|
||||
}
|
||||
|
||||
// Effect to close overlay tools on EscapealetteStats = Object.values(answers).reduce(
|
||||
// Effect to close overlay tools on Escape
|
||||
const paletteStats = Object.values(answers || {}).reduce(
|
||||
(acc, val) => {
|
||||
acc[val.status]++;
|
||||
return acc;
|
||||
|
||||
Reference in New Issue
Block a user