correction page quizzes
This commit is contained in:
parent
3470c7caf0
commit
0ccd3ed0ff
@ -225,7 +225,7 @@ export default function QuizzesClient({ initialCategories, stats: initialStats }
|
||||
const res = await fetch(`/api/categories/${id}`, { method: 'DELETE' })
|
||||
if (res.ok) {
|
||||
const cat = categories.find((c) => c.id === id)
|
||||
const removedQuizzes = cat?.subchapters.reduce((acc, s) => acc + s.quizzes.length, 0) ?? 0
|
||||
const removedQuizzes = cat?.subchapters.reduce((acc, s) => acc + (s.quizzes?.length ?? 0), 0) ?? 0
|
||||
setCategories((prev) => prev.filter((c) => c.id !== id))
|
||||
setStats((s) => ({
|
||||
...s,
|
||||
@ -274,7 +274,7 @@ export default function QuizzesClient({ initialCategories, stats: initialStats }
|
||||
setCategories((prev) =>
|
||||
prev.map((c) => {
|
||||
const sub = c.subchapters.find((s) => s.id === subId)
|
||||
if (sub) removedQuizzes = sub.quizzes.length
|
||||
if (sub) removedQuizzes = sub.quizzes?.length ?? 0
|
||||
return { ...c, subchapters: c.subchapters.filter((s) => s.id !== subId) }
|
||||
})
|
||||
)
|
||||
@ -393,7 +393,7 @@ export default function QuizzesClient({ initialCategories, stats: initialStats }
|
||||
) : (
|
||||
filteredCategories.map((category, index) => {
|
||||
const isExpanded = expandedCategories.has(category.id)
|
||||
const totalQuizCount = category.subchapters.reduce((acc, s) => acc + s.quizzes.length, 0)
|
||||
const totalQuizCount = category.subchapters.reduce((acc, s) => acc + (s.quizzes?.length ?? 0), 0)
|
||||
const isEditingCat = editingCategoryId === category.id
|
||||
const isConfirmingDelete = confirmDeleteCategoryId === category.id
|
||||
const isDeletingCat = deletingCategoryId === category.id
|
||||
@ -486,7 +486,7 @@ export default function QuizzesClient({ initialCategories, stats: initialStats }
|
||||
const isConfirmingDeleteSub = confirmDeleteSubchapterId === subchapter.id
|
||||
const isDeletingSub = deletingSubchapterId === subchapter.id
|
||||
const isUploading = uploadingSubchapterId === subchapter.id
|
||||
const quiz = subchapter.quizzes[0] ?? null
|
||||
const quiz = (subchapter.quizzes ?? [])[0] ?? null
|
||||
|
||||
return (
|
||||
<tr key={subchapter.id} className="border-b border-border/50 hover:bg-background-elevated/30 transition-colors">
|
||||
|
||||
@ -30,9 +30,19 @@ export default async function QuizzesPage() {
|
||||
.in('session_id', ids)
|
||||
: { count: 0 }
|
||||
|
||||
// Supabase peut retourner `quizzes: null` quand un sous-chapitre n'a aucun quiz —
|
||||
// on normalise en tableau vide pour éviter les crash .length côté client.
|
||||
const normalizedCategories = (categories ?? []).map((cat: any) => ({
|
||||
...cat,
|
||||
subchapters: (cat.subchapters ?? []).map((sub: any) => ({
|
||||
...sub,
|
||||
quizzes: sub.quizzes ?? [],
|
||||
})),
|
||||
}))
|
||||
|
||||
return (
|
||||
<QuizzesClient
|
||||
initialCategories={categories ?? []}
|
||||
initialCategories={normalizedCategories}
|
||||
stats={{
|
||||
totalQuizzes: totalQuizzes ?? 0,
|
||||
totalCategories: categories?.length ?? 0,
|
||||
|
||||
@ -140,21 +140,16 @@ export default function LoginPage() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Remember me + forgot password */}
|
||||
<div className="flex items-center justify-between">
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={rememberMe}
|
||||
onChange={(e) => setRememberMe(e.target.checked)}
|
||||
className="w-4 h-4 rounded border-border bg-background-elevated text-primary"
|
||||
/>
|
||||
<span className="text-sm text-text-secondary">Rester connecté</span>
|
||||
</label>
|
||||
<button type="button" className="text-sm text-primary hover:text-primary-light transition-colors">
|
||||
Mot de passe oublié ?
|
||||
</button>
|
||||
</div>
|
||||
{/* Remember me */}
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={rememberMe}
|
||||
onChange={(e) => setRememberMe(e.target.checked)}
|
||||
className="w-4 h-4 rounded border-border bg-background-elevated text-primary"
|
||||
/>
|
||||
<span className="text-sm text-text-secondary">Rester connecté</span>
|
||||
</label>
|
||||
|
||||
{/* Error message */}
|
||||
{error && (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user