diff --git a/src/pages/ProductDetail.tsx b/src/pages/ProductDetail.tsx index a245384..959ace6 100644 --- a/src/pages/ProductDetail.tsx +++ b/src/pages/ProductDetail.tsx @@ -68,6 +68,7 @@ export default function ProductDetail() { const [hasAccess, setHasAccess] = useState(false); const [checkingAccess, setCheckingAccess] = useState(true); const [expandedModules, setExpandedModules] = useState>(new Set()); + const [expandedLessonChapters, setExpandedLessonChapters] = useState>(new Set()); const [userReview, setUserReview] = useState(null); const [reviewModalOpen, setReviewModalOpen] = useState(false); const { addItem, items } = useCart(); @@ -138,6 +139,13 @@ export default function ProductDetail() { if (sorted.length > 0) { setExpandedModules(new Set([sorted[0].id])); } + + // Expand all lessons with chapters by default + const lessonsWithChapters = sorted + .flatMap(m => m.lessons) + .filter(l => l.chapters && l.chapters.length > 0) + .map(l => l.id); + setExpandedLessonChapters(new Set(lessonsWithChapters)); } }; @@ -222,8 +230,13 @@ export default function ProductDetail() { const isInCart = product ? items.some(item => item.id === product.id) : false; const formatChapterTime = (seconds: number) => { - const mins = Math.floor(seconds / 60); + const hours = Math.floor(seconds / 3600); + const mins = Math.floor((seconds % 3600) / 60); const secs = Math.floor(seconds % 60); + + if (hours > 0) { + return `${hours}:${String(mins).padStart(2, '0')}:${String(secs).padStart(2, '0')}`; + } return `${mins}:${String(secs).padStart(2, '0')}`; }; @@ -283,6 +296,16 @@ export default function ProductDetail() { setExpandedModules(newSet); }; + const toggleLessonChapters = (lessonId: string) => { + const newSet = new Set(expandedLessonChapters); + if (newSet.has(lessonId)) { + newSet.delete(lessonId); + } else { + newSet.add(lessonId); + } + setExpandedLessonChapters(newSet); + }; + if (loading) { return (
); } @@ -421,21 +444,39 @@ export default function ProductDetail() { {/* Lesson chapters (if any) */} {lesson.chapters && lesson.chapters.length > 0 && ( -
- {lesson.chapters.map((chapter, chapterIndex) => ( -
- - {formatChapterTime(chapter.time)} - - - + toggleLessonChapters(lesson.id)} + > + + + + {lesson.chapters.length} timeline item{lesson.chapters.length > 1 ? 's' : ''} + + {expandedLessonChapters.has(lesson.id) ? ( + + ) : ( + + )} + + +
+ {lesson.chapters.map((chapter, chapterIndex) => ( +
+ + {formatChapterTime(chapter.time)} + + + +
+ ))}
- ))} -
+ + )}
))}