generated from muhtadeetaron/nextjs-template
fix(ui): refactor results page for exam results logic
This commit is contained in:
@ -1,17 +1,10 @@
|
||||
// lib/gallery-views.tsx
|
||||
import Link from "next/link";
|
||||
import Image from "next/image";
|
||||
import { ExamAnswer } from "@/types/exam";
|
||||
import { GalleryViews } from "@/types/gallery";
|
||||
import { ExamResult } from "@/types/exam";
|
||||
|
||||
// Define the ExamResults type if not already defined
|
||||
interface ExamResults {
|
||||
score: number;
|
||||
totalQuestions: number;
|
||||
answers: ExamAnswer[]; // or more specific type based on your answer structure
|
||||
}
|
||||
|
||||
export const getResultViews = (examResults: ExamResults | null) => [
|
||||
export const getResultViews = (examResults: ExamResult | null) => [
|
||||
{
|
||||
id: 1,
|
||||
content: (
|
||||
@ -30,7 +23,8 @@ export const getResultViews = (examResults: ExamResults | null) => [
|
||||
<h2 className="text-6xl font-bold text-[#113678]">
|
||||
{examResults
|
||||
? (
|
||||
(examResults.score / examResults.totalQuestions) *
|
||||
(examResults.correct_answers_count /
|
||||
examResults.user_questions.length) *
|
||||
100
|
||||
).toFixed(1)
|
||||
: "0"}
|
||||
@ -59,8 +53,9 @@ export const getResultViews = (examResults: ExamResults | null) => [
|
||||
<h2 className="text-6xl font-bold text-[#113678]">
|
||||
{examResults
|
||||
? (
|
||||
((examResults.totalQuestions - examResults.score) /
|
||||
examResults.totalQuestions) *
|
||||
((examResults.user_questions.length -
|
||||
examResults.correct_answers_count) /
|
||||
examResults.user_questions.length) *
|
||||
100
|
||||
).toFixed(1)
|
||||
: "0"}
|
||||
@ -89,7 +84,8 @@ export const getResultViews = (examResults: ExamResults | null) => [
|
||||
<h2 className="text-6xl font-bold text-[#113678]">
|
||||
{examResults
|
||||
? (
|
||||
(examResults.answers.length / examResults.totalQuestions) *
|
||||
(examResults.user_answers.length /
|
||||
examResults.user_questions.length) *
|
||||
100
|
||||
).toFixed(1)
|
||||
: "0"}
|
||||
|
||||
Reference in New Issue
Block a user