@@ -56,6 +56,7 @@ export default function Home() {
5656 selectedQuestions ?? ( hasValidCustomQuestions ? customQuestionsValue : 0 ) ;
5757 const timerMinutes = selectedTimer ?? ( hasValidCustom ? customMinutesValue : 0 ) ;
5858
59+ // Load a random window of UCAT questions, optionally filtered by type.
5960 const loadQuestions = async ( limit : number , types : string [ ] ) => {
6061 if ( ! limit ) return [ ] ;
6162 const supabase = createClient ( ) ;
@@ -66,7 +67,7 @@ export default function Home() {
6667 }
6768 const { count, error : countError } = await countQuery ;
6869
69- if ( countError ) throw countError ;
70+ if ( countError ) throw new Error ( countError . message ) ;
7071 if ( ! count ) return [ ] ;
7172
7273 const safeLimit = Math . min ( limit , count ) ;
@@ -75,7 +76,9 @@ export default function Home() {
7576
7677 let dataQuery = supabase
7778 . from ( "Ucat" )
78- . select ( "id, question, answer1, answer2, answer3, answer4, answer5, correct_answer" )
79+ . select (
80+ 'id, question, "answer 1", "answer 2", "answer 3", "answer 4", "answer 5", correct_answer, type'
81+ )
7982 . order ( "id" , { ascending : true } )
8083 . range ( offset , offset + safeLimit - 1 ) ;
8184
@@ -85,15 +88,15 @@ export default function Home() {
8588
8689 const { data, error } = await dataQuery ;
8790
88- if ( error ) throw error ;
91+ if ( error ) throw new Error ( error . message ) ;
8992
9093 return ( data ?? [ ] ) . map ( ( row , index ) => {
9194 const options = [
92- row . answer1 ,
93- row . answer2 ,
94- row . answer3 ,
95- row . answer4 ,
96- row . answer5 ,
95+ row [ "answer 1" ] ,
96+ row [ "answer 2" ] ,
97+ row [ "answer 3" ] ,
98+ row [ "answer 4" ] ,
99+ row [ "answer 5" ] ,
97100 ]
98101 . map ( ( value ) => ( typeof value === "string" ? value . trim ( ) : "" ) )
99102 . filter ( Boolean ) ;
@@ -115,6 +118,7 @@ export default function Home() {
115118 } ) ;
116119 } ;
117120
121+ // Start a quiz session and fetch questions from Supabase.
118122 const handleStart = async ( ) => {
119123 if ( ! canStart ) return ;
120124 const selectedTypes = [
@@ -144,9 +148,11 @@ export default function Home() {
144148 setTimeRemaining ( null ) ;
145149 }
146150 } catch ( error ) {
147- setQuestionLoadError (
148- error instanceof Error ? error . message : "Failed to load UCAT questions."
149- ) ;
151+ if ( error && typeof error === "object" && "message" in error ) {
152+ setQuestionLoadError ( String ( error . message ) ) ;
153+ } else {
154+ setQuestionLoadError ( "Failed to load UCAT questions." ) ;
155+ }
150156 } finally {
151157 setIsLoadingQuestions ( false ) ;
152158 }
@@ -156,11 +162,12 @@ export default function Home() {
156162 if ( ! questions . length ) {
157163 return {
158164 correctCount : 0 ,
159- results : [ ] as { id : number ; isCorrect : boolean | null } [ ] ,
165+ results : [ ] as { id : number ; number : number ; isCorrect : boolean | null } [ ] ,
160166 } ;
161167 }
162168 const results = questions . map ( ( question , index ) => ( {
163169 id : question . id ,
170+ number : index + 1 ,
164171 isCorrect :
165172 answerResults [ index ] ??
166173 ( question . correctIndex === null
@@ -171,6 +178,7 @@ export default function Home() {
171178 return { correctCount, results } ;
172179 } , [ questions , selectedAnswers , answerResults ] ) ;
173180
181+ // Timer countdown for timed mode.
174182 useEffect ( ( ) => {
175183 if ( ! hasStarted || practiceMode !== "timed" || timeRemaining === null ) return ;
176184 if ( timeRemaining <= 0 ) return ;
@@ -180,6 +188,7 @@ export default function Home() {
180188 return ( ) => window . clearInterval ( intervalId ) ;
181189 } , [ hasStarted , practiceMode , timeRemaining ] ) ;
182190
191+ // Simple mm:ss formatter for timers.
183192 const formatSeconds = ( totalSeconds : number ) => {
184193 const minutes = Math . floor ( totalSeconds / 60 ) ;
185194 const seconds = totalSeconds % 60 ;
@@ -345,7 +354,7 @@ export default function Home() {
345354 : "incorrect"
346355 } `}
347356 >
348- Question { result . id } :{ " " }
357+ Question { result . number } :{ " " }
349358 { result . isCorrect === null
350359 ? "Unscored"
351360 : result . isCorrect
0 commit comments