Skip to content

PROD-2562 - handle the navigation away on the fcc's last step of a co… #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CoursesProviderData,
LearnLesson,
LearnModule,
LearnMyModuleProgress,
LessonProviderData,
MyCertificationProgressProviderData,
MyCertificationProgressStatus,
Expand Down Expand Up @@ -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<LearnLesson>|undefined = courseData?.modules.find(m => m.key === firstIncompleteModule?.module)?.lessons
if (!firstIncompleteModule || !moduleLessons) {
// case unknown, return
return
}

const completedLessons: Array<string> = 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 &&
Expand Down Expand Up @@ -270,6 +318,7 @@ const FreeCodeCamp: FC<{}> = () => {
lesson={lesson}
onFccLessonChange={handleFccLessonReady}
onFccLessonComplete={handleFccLessonComplete}
onFccLastLessonNavigation={handleFccLastLessonNavigation}
/>
</div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion src-ts/tools/learn/free-code-camp/fcc-frame/FccFrame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ const FreecodecampIfr: FC<any> = memo((params: any) => (
<iframe
className={styles.iframe}
ref={params.frameRef}
title='FreeCodeCamp.org Course'
/>
))

interface FccFrameProps {
lesson?: LearnLessonMeta
onFccLastLessonNavigation: () => void
onFccLessonChange: (path: string) => void
onFccLessonComplete: () => void
}
Expand Down Expand Up @@ -51,6 +53,10 @@ const FccFrame: FC<FccFrameProps> = (props: FccFrameProps) => {

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

if (eventName === 'fcc:nav:last-challenge') {
props.onFccLastLessonNavigation()
}

if (eventName === 'fcc:challenge:completed') {
props.onFccLessonComplete()
}
Expand All @@ -65,7 +71,7 @@ const FccFrame: FC<FccFrameProps> = (props: FccFrameProps) => {
return () => {
window.removeEventListener('message', handleEvent, false)
}
}, [frameRef, props.onFccLessonChange, props.onFccLessonComplete])
}, [frameRef, props.onFccLastLessonNavigation, props.onFccLessonChange, props.onFccLessonComplete])

return (
<FreecodecampIfr frameRef={frameRef} />
Expand Down