Skip to content

Commit 14acb0c

Browse files
authored
Merge pull request #214 from topcoder-platform/PROD-2562_certification_navigation_handle
PROD-2562 - handle the navigation away on the fcc's last step of a co…
2 parents 4cb96f3 + afcc5d9 commit 14acb0c

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
CoursesProviderData,
2525
LearnLesson,
2626
LearnModule,
27+
LearnMyModuleProgress,
2728
LessonProviderData,
2829
useCourses,
2930
useLessonProvider,
@@ -197,6 +198,53 @@ const FreeCodeCamp: FC<{}> = () => {
197198
}
198199
}
199200

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+
200248
useEffect(() => {
201249
if (
202250
certificateProgress &&
@@ -292,6 +340,7 @@ const FreeCodeCamp: FC<{}> = () => {
292340
lesson={lesson}
293341
onFccLessonChange={handleFccLessonReady}
294342
onFccLessonComplete={handleFccLessonComplete}
343+
onFccLastLessonNavigation={handleFccLastLessonNavigation}
295344
/>
296345
</div>
297346
</div>

src-ts/tools/learn/free-code-camp/fcc-frame/FccFrame.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ const FreecodecampIfr: FC<any> = memo((params: any) => (
99
<iframe
1010
className={styles.iframe}
1111
ref={params.frameRef}
12+
title='FreeCodeCamp.org Course'
1213
/>
1314
))
1415

1516
interface FccFrameProps {
1617
lesson?: LearnLessonMeta
18+
onFccLastLessonNavigation: () => void
1719
onFccLessonChange: (path: string) => void
1820
onFccLessonComplete: () => void
1921
}
@@ -51,6 +53,10 @@ const FccFrame: FC<FccFrameProps> = (props: FccFrameProps) => {
5153

5254
const {event: eventName, data}: {data: {path: string}, event: string } = JSON.parse(jsonData)
5355

56+
if (eventName === 'fcc:nav:last-challenge') {
57+
props.onFccLastLessonNavigation()
58+
}
59+
5460
if (eventName === 'fcc:challenge:completed') {
5561
props.onFccLessonComplete()
5662
}
@@ -65,7 +71,7 @@ const FccFrame: FC<FccFrameProps> = (props: FccFrameProps) => {
6571
return () => {
6672
window.removeEventListener('message', handleEvent, false)
6773
}
68-
}, [frameRef, props.onFccLessonChange, props.onFccLessonComplete])
74+
}, [frameRef, props.onFccLastLessonNavigation, props.onFccLessonChange, props.onFccLessonComplete])
6975

7076
return (
7177
<FreecodecampIfr frameRef={frameRef} />

0 commit comments

Comments
 (0)