1- import { Link } from '@/i18n/routing' ;
2- import { getActiveQuizzes } from '@/db/queries/quiz' ;
3-
4- type PageProps = { params : Promise < { locale : string } > ; } ;
1+ import { getActiveQuizzes , getUserQuizzesProgress } from '@/db/queries/quiz' ;
2+ import { getCurrentUser } from '@/lib/auth' ;
3+ import QuizzesSection from '@/components/quiz/QuizzesSection' ;
54
5+ type PageProps = { params : Promise < { locale : string } > } ;
66
77export const dynamic = 'force-dynamic' ;
88
99export default async function QuizzesPage ( { params } : PageProps ) {
1010 const { locale } = await params ;
11+ const session = await getCurrentUser ( ) ;
12+
1113 const quizzes = await getActiveQuizzes ( locale ) ;
1214
15+ let userProgressMap : Record < string , any > = { } ;
16+
17+ if ( session ?. id ) {
18+ const progressMapData = await getUserQuizzesProgress ( session . id ) ;
19+ userProgressMap = Object . fromEntries ( progressMapData ) ;
20+ }
21+
1322 if ( ! quizzes . length ) {
1423 return (
15- < div className = "mx-auto max-w-4xl py-12" >
24+ < div className = "mx-auto max-w-5xl py-12" >
1625 < h1 className = "text-3xl font-bold mb-4" > Quizzes</ h1 >
1726 < p className = "text-gray-600 dark:text-gray-400" >
1827 No quizzes available yet. Please check back soon.
@@ -22,54 +31,18 @@ export default async function QuizzesPage({ params }: PageProps) {
2231 }
2332
2433 return (
25- < div className = "mx-auto max-w-4xl py-12" >
26- < div className = "flex items-center justify-between mb-6" >
27- < div >
28- < p className = "text-sm text-blue-600 dark:text-blue-400 font-semibold" >
29- Practice
30- </ p >
31- < h1 className = "text-3xl font-bold" > Quizzes</ h1 >
32- < p className = "text-gray-600 dark:text-gray-400" >
33- Choose a quiz to test your knowledge.
34- </ p >
35- </ div >
34+ < div className = "mx-auto max-w-5xl py-12" >
35+ < div className = "mb-8" >
36+ < p className = "text-sm text-blue-600 dark:text-blue-400 font-semibold" >
37+ Practice
38+ </ p >
39+ < h1 className = "text-3xl font-bold" > Quizzes</ h1 >
40+ < p className = "text-gray-600 dark:text-gray-400" >
41+ Choose a quiz to test your knowledge.
42+ </ p >
3643 </ div >
3744
38- < div className = "grid gap-4" >
39- { quizzes . map ( ( quiz ) => (
40- < div
41- key = { quiz . id }
42- className = "rounded-xl border border-gray-200 dark:border-neutral-800 bg-white dark:bg-neutral-900 p-5 shadow-sm"
43- >
44- < div className = "flex items-center justify-between gap-3" >
45- < div className = "space-y-1" >
46- < h2 className = "text-xl font-semibold" >
47- { quiz . title ?? quiz . slug }
48- </ h2 >
49- { quiz . description && (
50- < p className = "text-gray-600 dark:text-gray-400 text-sm" >
51- { quiz . description }
52- </ p >
53- ) }
54- < div className = "flex gap-3 text-xs text-gray-500" >
55- < span > { quiz . questionsCount } questions</ span >
56- { quiz . timeLimitSeconds && (
57- < span >
58- { Math . floor ( quiz . timeLimitSeconds / 60 ) } min limit
59- </ span >
60- ) }
61- </ div >
62- </ div >
63- < Link
64- href = { `/quiz/${ quiz . slug } ` }
65- className = "inline-flex items-center rounded-lg bg-blue-600 text-white px-3 py-2 text-sm font-medium hover:bg-blue-500 transition"
66- >
67- Start quiz
68- </ Link >
69- </ div >
70- </ div >
71- ) ) }
72- </ div >
45+ < QuizzesSection quizzes = { quizzes } userProgressMap = { userProgressMap } />
7346 </ div >
7447 ) ;
7548}
0 commit comments