generated from muhtadeetaron/nextjs-template
fix(api): fix api logic for exam screen
needs more work for the timercontext
This commit is contained in:
@ -14,14 +14,14 @@ import DestructibleAlert from "@/components/DestructibleAlert";
|
||||
import BackgroundWrapper from "@/components/BackgroundWrapper";
|
||||
import { API_URL, getToken } from "@/lib/auth";
|
||||
import { useExam } from "@/context/ExamContext";
|
||||
import { Question } from "@/types/exam";
|
||||
import { Test } from "@/types/exam";
|
||||
import { Metadata } from "@/types/exam";
|
||||
|
||||
function PretestPageContent() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const { startExam, setCurrentExam } = useExam();
|
||||
const [examData, setExamData] = useState<Question[]>();
|
||||
const { startExam } = useExam();
|
||||
const [examData, setExamData] = useState<Test>();
|
||||
|
||||
// Get params from URL search params
|
||||
const id = searchParams.get("test_id") || "";
|
||||
@ -55,7 +55,7 @@ function PretestPageContent() {
|
||||
|
||||
const data = await questionResponse.json();
|
||||
const fetchedMetadata: Metadata = data.metadata;
|
||||
const fetchedQuestions: Question[] = data.questions;
|
||||
const fetchedQuestions: Test = data.questions;
|
||||
|
||||
setMetadata(fetchedMetadata);
|
||||
setExamData(fetchedQuestions);
|
||||
@ -123,9 +123,9 @@ function PretestPageContent() {
|
||||
function handleStartExam() {
|
||||
if (!examData) return;
|
||||
|
||||
setCurrentExam(examData);
|
||||
startExam(examData);
|
||||
router.push(`/exam/${id}?test_id=${metadata?.test_id}`);
|
||||
router.push(
|
||||
`/exam/${id}?type=${type}&test_id=${metadata?.test_id}&attempt_id=${metadata?.attempt_id}`
|
||||
);
|
||||
}
|
||||
return (
|
||||
<BackgroundWrapper>
|
||||
|
||||
Reference in New Issue
Block a user