@@ -24,6 +24,7 @@ import {
24
24
CoursesProviderData ,
25
25
LearnLesson ,
26
26
LearnModule ,
27
+ LearnMyModuleProgress ,
27
28
LessonProviderData ,
28
29
useCourses ,
29
30
useLessonProvider ,
@@ -197,6 +198,53 @@ const FreeCodeCamp: FC<{}> = () => {
197
198
}
198
199
}
199
200
201
+ /**
202
+ * Handle the navigation away from the last step of the course in the FCC frame
203
+ * @returns
204
+ */
205
+ function handleFccLastLessonNavigation ( ) : void {
206
+ if ( ! certificateProgress ) {
207
+ return
208
+ }
209
+
210
+ // course is completed, return user to course completed screen
211
+ if ( certificateProgress . courseProgressPercentage === 100 ) {
212
+ const completedPath : string = getCertificationCompletedPath (
213
+ providerParam ,
214
+ certificationParam
215
+ )
216
+
217
+ navigate ( completedPath )
218
+ return
219
+ }
220
+
221
+ // course is not completed yet,
222
+ // so we find the first incomplete lesson
223
+ // and redirect user to it for a continuous flow
224
+ const firstIncompleteModule : LearnMyModuleProgress | undefined = certificateProgress . modules . find ( m => m . completedPercentage !== 100 )
225
+ const moduleLessons : Array < LearnLesson > | undefined = courseData ?. modules . find ( m => m . key === firstIncompleteModule ?. module ) ?. lessons
226
+ if ( ! firstIncompleteModule || ! moduleLessons ) {
227
+ // case unknown, return
228
+ return
229
+ }
230
+
231
+ const completedLessons : Array < string > = firstIncompleteModule . completedLessons . map ( l => l . dashedName )
232
+ const firstIncompleteLesson : LearnLesson | undefined = moduleLessons . find ( l => ! completedLessons . includes ( l . dashedName ) )
233
+ if ( ! firstIncompleteLesson ) {
234
+ // case unknown, return
235
+ return
236
+ }
237
+
238
+ const nextLessonPath : string = getFccLessonPath (
239
+ providerParam ,
240
+ certificationParam ,
241
+ firstIncompleteModule . module ?? '' ,
242
+ firstIncompleteLesson . dashedName ?? ''
243
+ )
244
+
245
+ navigate ( nextLessonPath )
246
+ }
247
+
200
248
useEffect ( ( ) => {
201
249
if (
202
250
certificateProgress &&
@@ -292,6 +340,7 @@ const FreeCodeCamp: FC<{}> = () => {
292
340
lesson = { lesson }
293
341
onFccLessonChange = { handleFccLessonReady }
294
342
onFccLessonComplete = { handleFccLessonComplete }
343
+ onFccLastLessonNavigation = { handleFccLastLessonNavigation }
295
344
/>
296
345
</ div >
297
346
</ div >
0 commit comments