11import { Cinzel } from "next/font/google" ;
22import { useState } from "react" ;
3- import { helloWorldQuiz } from "@/data/quizzes/01-hello-world " ;
3+ import { QuizData } from "@/lib/types/types " ;
44
55const cinzel = Cinzel ( { subsets : [ "latin" ] , weight : [ "700" ] } ) ;
66
7- export default function TutorialQuiz ( ) {
7+ type QuizProps = {
8+ quizData : QuizData ;
9+ } ;
10+
11+ export default function Quiz ( { quizData } : QuizProps ) {
812 const [ questionNumber , setQuestionNumber ] = useState < number > ( 0 ) ;
913 const [ selectedOption , setSelectedOption ] = useState < string | null > ( null ) ;
1014 const [ isCorrect , setIsCorrect ] = useState < boolean | null > ( null ) ;
1115 const [ score , setScore ] = useState ( 0 ) ;
1216 const [ showResults , setShowResults ] = useState ( false ) ;
1317
14- const currentQuestion = helloWorldQuiz . questions [ questionNumber ] ;
18+ const currentQuestion = quizData . questions [ questionNumber ] ;
1519
1620 const handleOptionClick = ( option : string ) => {
1721 if ( selectedOption ) return ;
1822 setSelectedOption ( option ) ;
1923
24+ // 1. Check Correctness
2025 const correct = option === currentQuestion . correctAnswer ;
2126 setIsCorrect ( correct ) ;
2227
@@ -29,7 +34,7 @@ export default function TutorialQuiz() {
2934 setTimeout ( ( ) => {
3035 const nextIndex = questionNumber + 1 ;
3136
32- if ( nextIndex < helloWorldQuiz . questions . length ) {
37+ if ( nextIndex < quizData . questions . length ) {
3338 setQuestionNumber ( nextIndex ) ;
3439 setSelectedOption ( null ) ;
3540 setIsCorrect ( null ) ;
@@ -50,16 +55,16 @@ export default function TutorialQuiz() {
5055 return (
5156 < div className = "mt-12 p-8 border-2 border-amber-800/50 rounded-xl bg-amber-50/50 shadow-inner shadow-amber-900/20" >
5257 < h2 className = { `text-3xl font-bold text-center mb-6 text-amber-900 ${ cinzel . className } ` } >
53- { helloWorldQuiz . title }
58+ { quizData . title }
5459 </ h2 >
5560
56- { /* 5. Conditional Rendering: Results vs Question */ }
5761 { showResults ? (
5862 < div className = "text-center space-y-6 animate-fade-in" >
63+ { /* Results */ }
5964 < p className = "text-2xl text-amber-950" > Quest Complete!</ p >
6065 < p className = "text-xl" >
6166 You scored < span className = "font-bold" > { score } </ span > out of{ " " }
62- < span className = "font-bold" > { helloWorldQuiz . questions . length } </ span >
67+ < span className = "font-bold" > { quizData . questions . length } </ span >
6368 </ p >
6469 < button
6570 onClick = { resetQuiz }
@@ -73,7 +78,7 @@ export default function TutorialQuiz() {
7378 { /* Score Tracker Display */ }
7479 < div className = "flex justify-between text-amber-800 font-serif italic" >
7580 < span >
76- Question { questionNumber + 1 } of { helloWorldQuiz . questions . length }
81+ Question { questionNumber + 1 } of { quizData . questions . length }
7782 </ span >
7883 < span > Score: { score } </ span >
7984 </ div >
0 commit comments