diff --git a/src/App.tsx b/src/App.tsx index 9101255..9a20ba2 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -57,7 +57,7 @@ const App = () => ( } /> } /> } /> - } /> + } /> } /> } /> } /> diff --git a/src/pages/Bootcamp.tsx b/src/pages/Bootcamp.tsx index 75b8ab3..4833c63 100644 --- a/src/pages/Bootcamp.tsx +++ b/src/pages/Bootcamp.tsx @@ -55,7 +55,7 @@ interface UserReview { } export default function Bootcamp() { - const { slug } = useParams<{ slug: string }>(); + const { slug, lessonId } = useParams<{ slug: string; lessonId?: string }>(); const navigate = useNavigate(); const { user, loading: authLoading } = useAuth(); @@ -134,7 +134,20 @@ export default function Bootcamp() { })); setModules(sortedModules); - if (sortedModules.length > 0 && sortedModules[0].lessons.length > 0) { + // Select lesson based on URL parameter or default to first lesson + const allLessons = sortedModules.flatMap(m => m.lessons); + + if (lessonId) { + // Find the lesson by ID from URL + const lessonFromUrl = allLessons.find(l => l.id === lessonId); + if (lessonFromUrl) { + setSelectedLesson(lessonFromUrl); + } else if (allLessons.length > 0) { + // If lesson not found, default to first lesson + setSelectedLesson(allLessons[0]); + } + } else if (allLessons.length > 0 && sortedModules[0].lessons.length > 0) { + // No lessonId in URL, select first lesson setSelectedLesson(sortedModules[0].lessons[0]); } } @@ -170,6 +183,12 @@ export default function Bootcamp() { return progress.some(p => p.lesson_id === lessonId); }; + const handleSelectLesson = (lesson: Lesson) => { + setSelectedLesson(lesson); + // Update URL without full page reload + navigate(`/bootcamp/${slug}/${lesson.id}`); + }; + const markAsCompleted = async () => { if (!selectedLesson || !user || !product) return; @@ -347,7 +366,7 @@ export default function Bootcamp() { key={lesson.id} onClick={() => { if (isReleased) { - setSelectedLesson(lesson); + handleSelectLesson(lesson); setMobileMenuOpen(false); } }}