fix(ui): refactor results page for exam results logic

This commit is contained in:
shafin-r
2025-08-31 23:27:32 +06:00
parent 7df2708db7
commit 5507602031
9 changed files with 127 additions and 444 deletions

View File

@ -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"}