diff --git a/src/components/admin/ChaptersEditor.tsx b/src/components/admin/ChaptersEditor.tsx index 8d9eb69..27c4ed6 100644 --- a/src/components/admin/ChaptersEditor.tsx +++ b/src/components/admin/ChaptersEditor.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; @@ -21,6 +21,15 @@ export function ChaptersEditor({ chapters, onChange, className = '' }: ChaptersE chapters.length > 0 ? chapters : [{ time: 0, title: '' }] ); + // Sync internal state when prop changes (e.g., when switching between lessons) + useEffect(() => { + if (chapters.length > 0) { + setChaptersList(chapters); + } else { + setChaptersList([{ time: 0, title: '' }]); + } + }, [chapters]); + const updateTime = (index: number, value: string) => { const newChapters = [...chaptersList]; const parts = value.split(':').map(Number);