Skip to content

Commit afcc5d9

Browse files
committed
PROD-2562 - handle the navigation away on the fcc's last step of a course
1 parent d07e2d7 commit afcc5d9

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
@@ -14,6 +14,7 @@ import {
1414
CoursesProviderData,
1515
LearnLesson,
1616
LearnModule,
17+
LearnMyModuleProgress,
1718
LessonProviderData,
1819
MyCertificationProgressProviderData,
1920
MyCertificationProgressStatus,
@@ -175,6 +176,53 @@ const FreeCodeCamp: FC<{}> = () => {
175176
}
176177
}
177178

179+
/**
180+
* Handle the navigation away from the last step of the course in the FCC frame
181+
* @returns
182+
*/
183+
function handleFccLastLessonNavigation(): void {
184+
if (!certificateProgress) {
185+
return
186+
}
187+
188+
// course is completed, return user to course completed screen
189+
if (certificateProgress.courseProgressPercentage === 100) {
190+
const completedPath: string = getCertificationCompletedPath(
191+
providerParam,
192+
certificationParam
193+
)
194+
195+
navigate(completedPath)
196+
return
197+
}
198+
199+
// course is not completed yet,
200+
// so we find the first incomplete lesson
201+
// and redirect user to it for a continuous flow
202+
const firstIncompleteModule: LearnMyModuleProgress|undefined = certificateProgress.modules.find(m => m.completedPercentage !== 100)
203+
const moduleLessons: Array<LearnLesson>|undefined = courseData?.modules.find(m => m.key === firstIncompleteModule?.module)?.lessons
204+
if (!firstIncompleteModule || !moduleLessons) {
205+
// case unknown, return
206+
return
207+
}
208+
209+
const completedLessons: Array<string> = firstIncompleteModule.completedLessons.map(l => l.dashedName)
210+
const firstIncompleteLesson: LearnLesson|undefined = moduleLessons.find(l => !completedLessons.includes(l.dashedName))
211+
if (!firstIncompleteLesson) {
212+
// case unknown, return
213+
return
214+
}
215+
216+
const nextLessonPath: string = getFccLessonPath(
217+
providerParam,
218+
certificationParam,
219+
firstIncompleteModule.module ?? '',
220+
firstIncompleteLesson.dashedName ?? ''
221+
)
222+
223+
navigate(nextLessonPath)
224+
}
225+
178226
useEffect(() => {
179227
if (
180228
certificateProgress &&
@@ -270,6 +318,7 @@ const FreeCodeCamp: FC<{}> = () => {
270318
lesson={lesson}
271319
onFccLessonChange={handleFccLessonReady}
272320
onFccLessonComplete={handleFccLessonComplete}
321+
onFccLastLessonNavigation={handleFccLastLessonNavigation}
273322
/>
274323
</div>
275324
</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)