Skip to content

TCA-796 fcc last lesson callback -> dev #435

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 4 commits into from
Dec 9, 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
2 changes: 2 additions & 0 deletions src-ts/tools/learn/course-details/CourseDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const CourseDetailsPage: FC<{}> = () => {
const {
certificationProgress: progress,
ready: progressReady,
setCertificateProgress,
}: UserCertificationProgressProviderData = useGetUserCertificationProgress(
profile?.userId,
routeParams.provider,
Expand Down Expand Up @@ -214,6 +215,7 @@ const CourseDetailsPage: FC<{}> = () => {
progress={progress}
progressReady={progressReady}
profile={profile}
setCertificateProgress={setCertificateProgress}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface CourseCurriculumProps {
profile?: UserProfile
progress?: LearnUserCertificationProgress
progressReady?: boolean
setCertificateProgress: (d: LearnUserCertificationProgress) => void
}

const CourseCurriculum: FC<CourseCurriculumProps> = (props: CourseCurriculumProps) => {
Expand Down Expand Up @@ -108,7 +109,7 @@ const CourseCurriculum: FC<CourseCurriculumProps> = (props: CourseCurriculumProp
}

if (!props.progress?.id) {
await userCertificationProgressStartAsync(
const progress: LearnUserCertificationProgress = await userCertificationProgressStartAsync(
props.profile.userId,
props.course.certificationId,
props.course.id,
Expand All @@ -117,6 +118,9 @@ const CourseCurriculum: FC<CourseCurriculumProps> = (props: CourseCurriculumProp
module: props.course.modules[0].meta.dashedName,
},
)

// update progress with data returned from calling the start progress endpoint
props.setCertificateProgress(progress)
} else {
await userCertificationProgressUpdateAsync(
props.progress.id,
Expand Down
11 changes: 6 additions & 5 deletions src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { FccFrame } from './fcc-frame'
import { FccSidebar } from './fcc-sidebar'
import { TitleNav } from './title-nav'
import styles from './FreeCodeCamp.module.scss'
import { debounce } from 'lodash'

const FreeCodeCamp: FC<{}> = () => {

Expand Down Expand Up @@ -211,7 +212,7 @@ const FreeCodeCamp: FC<{}> = () => {
profile?.userId,
])

const handleFccLessonComplete: (challengeUuid: string) => void = useCallback((challengeUuid: string) => {
const handleFccLessonComplete: (challengeUuid: string) => void = useCallback(debounce((challengeUuid: string) => {

const currentLesson: { [key: string]: string } = {
lesson: lessonParam,
Expand Down Expand Up @@ -239,7 +240,7 @@ const FreeCodeCamp: FC<{}> = () => {

})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
}, 30), [
certificateProgress,
lessonParam,
moduleParam,
Expand Down Expand Up @@ -280,14 +281,14 @@ const FreeCodeCamp: FC<{}> = () => {
* Handle the navigation away from the last step of the course in the FCC frame
* @returns
*/
const handleFccLastLessonNavigation: () => void = useCallback(() => {
const handleFccLastLessonNavigation: () => void = useCallback(debounce(() => {

if (!certificateProgress) {
return
}

// course is completed, return user to course completed screen
if (certificateProgress.courseProgressPercentage === 100) {
if (certificateProgress.status === UserCertificationProgressStatus.completed) {
const completedPath: string = getCertificationCompletedPath(
providerParam,
certificationParam,
Expand Down Expand Up @@ -326,7 +327,7 @@ const FreeCodeCamp: FC<{}> = () => {

navigate(nextLessonPath)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
}, 30), [
certificateProgress,
certificationParam,
courseData?.modules,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ export function useGetUserCertificationProgress(
isPaused: () => !userId || !certification,
})

const certificationProgress: LearnUserCertificationProgress | undefined = find(data, { certification })

return {
certificationProgress: find(data, { certification }),
certificationProgress,
loading: !!userId && !data && !error,
ready: !userId || data || error,
ready: !userId || !!data || !!error,
refetch: () => mutate(),
setCertificateProgress: progress => mutate([progress]),
}
Expand Down