diff --git a/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx b/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx index 351ab9d26..945484d6d 100644 --- a/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx +++ b/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx @@ -14,6 +14,7 @@ import { CoursesProviderData, LearnLesson, LearnModule, + LearnMyModuleProgress, LessonProviderData, MyCertificationProgressProviderData, MyCertificationProgressStatus, @@ -175,6 +176,53 @@ const FreeCodeCamp: FC<{}> = () => { } } + /** + * Handle the navigation away from the last step of the course in the FCC frame + * @returns + */ + function handleFccLastLessonNavigation(): void { + if (!certificateProgress) { + return + } + + // course is completed, return user to course completed screen + if (certificateProgress.courseProgressPercentage === 100) { + const completedPath: string = getCertificationCompletedPath( + providerParam, + certificationParam + ) + + navigate(completedPath) + return + } + + // course is not completed yet, + // so we find the first incomplete lesson + // and redirect user to it for a continuous flow + const firstIncompleteModule: LearnMyModuleProgress|undefined = certificateProgress.modules.find(m => m.completedPercentage !== 100) + const moduleLessons: Array|undefined = courseData?.modules.find(m => m.key === firstIncompleteModule?.module)?.lessons + if (!firstIncompleteModule || !moduleLessons) { + // case unknown, return + return + } + + const completedLessons: Array = firstIncompleteModule.completedLessons.map(l => l.dashedName) + const firstIncompleteLesson: LearnLesson|undefined = moduleLessons.find(l => !completedLessons.includes(l.dashedName)) + if (!firstIncompleteLesson) { + // case unknown, return + return + } + + const nextLessonPath: string = getFccLessonPath( + providerParam, + certificationParam, + firstIncompleteModule.module ?? '', + firstIncompleteLesson.dashedName ?? '' + ) + + navigate(nextLessonPath) + } + useEffect(() => { if ( certificateProgress && @@ -270,6 +318,7 @@ const FreeCodeCamp: FC<{}> = () => { lesson={lesson} onFccLessonChange={handleFccLessonReady} onFccLessonComplete={handleFccLessonComplete} + onFccLastLessonNavigation={handleFccLastLessonNavigation} /> diff --git a/src-ts/tools/learn/free-code-camp/fcc-frame/FccFrame.tsx b/src-ts/tools/learn/free-code-camp/fcc-frame/FccFrame.tsx index e8f423577..8eedab58d 100755 --- a/src-ts/tools/learn/free-code-camp/fcc-frame/FccFrame.tsx +++ b/src-ts/tools/learn/free-code-camp/fcc-frame/FccFrame.tsx @@ -9,11 +9,13 @@ const FreecodecampIfr: FC = memo((params: any) => (