generated from muhtadeetaron/nextjs-template
fix(exam): fix startexam function (not finding examdata)
This commit is contained in:
@ -130,17 +130,19 @@ const page = () => {
|
|||||||
className="flex bg-[#113768] rounded-[8] py-2 px-4 justify-between items-center"
|
className="flex bg-[#113768] rounded-[8] py-2 px-4 justify-between items-center"
|
||||||
>
|
>
|
||||||
<div className=" flex gap-3 items-center">
|
<div className=" flex gap-3 items-center">
|
||||||
<h2 className="font-medium text-lg text-white">
|
<h2 className="font-medium text-sm text-white">
|
||||||
{user.rank}
|
{user.rank}
|
||||||
</h2>
|
</h2>
|
||||||
<Avatar className="bg-slate-300 w-6 h-6">
|
<Avatar className="bg-slate-300 w-6 h-6">
|
||||||
<AvatarFallback className="text-md font-semibold">
|
<AvatarFallback className="text-sm font-semibold">
|
||||||
{user.name.charAt(0).toUpperCase()}
|
{user.name.charAt(0).toUpperCase()}
|
||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<h3 className="font-medium text-sm text-white">You</h3>
|
<h3 className="font-medium text-sm text-white">You</h3>
|
||||||
</div>
|
</div>
|
||||||
<p className="font-medium text-white/70">{user.points}pt</p>
|
<p className="font-medium text-white/70 text-sm">
|
||||||
|
{user.points}pt
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</section>
|
</section>
|
||||||
@ -154,9 +156,9 @@ const page = () => {
|
|||||||
className="flex border-2 border-[#c5dbf8] rounded-[8] py-2 px-4 justify-between items-center"
|
className="flex border-2 border-[#c5dbf8] rounded-[8] py-2 px-4 justify-between items-center"
|
||||||
>
|
>
|
||||||
<div className="flex gap-3 items-center">
|
<div className="flex gap-3 items-center">
|
||||||
<h2 className="font-medium text-lg">{idx + 1}</h2>
|
<h2 className="font-medium text-sm">{idx + 1}</h2>
|
||||||
<Avatar className="bg-slate-300 w-6 h-6">
|
<Avatar className="bg-slate-300 w-6 h-6">
|
||||||
<AvatarFallback className="text-md font-semibold">
|
<AvatarFallback className="text-sm font-semibold">
|
||||||
{user.name.charAt(0).toUpperCase()}
|
{user.name.charAt(0).toUpperCase()}
|
||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
@ -164,7 +166,7 @@ const page = () => {
|
|||||||
{user.name.split(" ").slice(0, 2).join(" ")}
|
{user.name.split(" ").slice(0, 2).join(" ")}
|
||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<p className="font-medium text-[#000]/40">
|
<p className="font-medium text-[#000]/40 text-sm">
|
||||||
{user.points}pt
|
{user.points}pt
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -82,10 +82,9 @@ export default function PretestPage() {
|
|||||||
|
|
||||||
function handleStartExam() {
|
function handleStartExam() {
|
||||||
setCurrentExam(examData);
|
setCurrentExam(examData);
|
||||||
startExam();
|
startExam(examData); // Pass examData directly
|
||||||
router.push(`/exam/${id}?time=${metadata?.metadata.duration}`);
|
router.push(`/exam/${id}?time=${metadata?.metadata.duration}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BackgroundWrapper>
|
<BackgroundWrapper>
|
||||||
<div className="min-h-screen flex flex-col justify-between">
|
<div className="min-h-screen flex flex-col justify-between">
|
||||||
|
|||||||
@ -110,7 +110,7 @@ const Header = ({
|
|||||||
</AvatarFallback>
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<span className={styles.text}>
|
<span className={styles.text}>
|
||||||
Hello {userData?.name ? userData.name.split(" ")[0] : ""}
|
Hello, {userData?.name ? userData.name.split(" ")[0] : ""}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -30,16 +30,18 @@ const QuestionItem = (props: QuestionItemProps) => {
|
|||||||
{question.id}. {question.question}
|
{question.id}. {question.question}
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<div className="flex justify-between items-center mb-4">
|
{isExam && (
|
||||||
<div></div>
|
<div className="flex justify-between items-center mb-4">
|
||||||
<button onClick={() => setBookmark(!bookmark)}>
|
<div></div>
|
||||||
{bookmark ? (
|
<button onClick={() => setBookmark(!bookmark)}>
|
||||||
<BookmarkCheck size={25} color="#113768" />
|
{bookmark ? (
|
||||||
) : (
|
<BookmarkCheck size={25} color="#113768" />
|
||||||
<Bookmark size={25} color="#113768" />
|
) : (
|
||||||
)}
|
<Bookmark size={25} color="#113768" />
|
||||||
</button>
|
)}
|
||||||
</div>
|
</button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{isExam ? (
|
{isExam ? (
|
||||||
<div className="flex flex-col gap-4 items-start">
|
<div className="flex flex-col gap-4 items-start">
|
||||||
@ -70,7 +72,7 @@ const QuestionItem = (props: QuestionItemProps) => {
|
|||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<div className="flex flex-col gap-3">
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
<div></div>
|
<div></div>
|
||||||
|
|
||||||
@ -121,7 +123,7 @@ const QuestionItem = (props: QuestionItemProps) => {
|
|||||||
<h3 className="text-lg font-bold text-black/40">Solution:</h3>
|
<h3 className="text-lg font-bold text-black/40">Solution:</h3>
|
||||||
<p className="text-lg">{question.solution}</p>
|
<p className="text-lg">{question.solution}</p>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -86,18 +86,21 @@ export const ExamProvider: React.FC<{ children: ReactNode }> = ({
|
|||||||
setCurrentAttemptState(null);
|
setCurrentAttemptState(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const startExam = () => {
|
const startExam = (exam?: Exam) => {
|
||||||
if (!currentExam) {
|
const examToUse = exam || currentExam;
|
||||||
|
|
||||||
|
if (!examToUse) {
|
||||||
console.warn("No exam selected, redirecting to /unit");
|
console.warn("No exam selected, redirecting to /unit");
|
||||||
router.push("/unit");
|
router.push("/unit");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const attempt: ExamAttempt = {
|
const attempt: ExamAttempt = {
|
||||||
examId: currentExam.id,
|
examId: examToUse.id,
|
||||||
exam: currentExam,
|
exam: examToUse,
|
||||||
answers: [],
|
answers: [],
|
||||||
startTime: new Date(),
|
startTime: new Date(),
|
||||||
|
totalQuestions: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
setCurrentAttemptState(attempt);
|
setCurrentAttemptState(attempt);
|
||||||
|
|||||||
Reference in New Issue
Block a user