diff --git a/src-ts/tools/learn/course-details/CourseDetailsPage.tsx b/src-ts/tools/learn/course-details/CourseDetailsPage.tsx index 1af5be961..ef9a2836b 100644 --- a/src-ts/tools/learn/course-details/CourseDetailsPage.tsx +++ b/src-ts/tools/learn/course-details/CourseDetailsPage.tsx @@ -48,6 +48,7 @@ const CourseDetailsPage: FC<{}> = () => { const { certificationProgress: progress, ready: progressReady, + setCertificateProgress, }: UserCertificationProgressProviderData = useGetUserCertificationProgress( profile?.userId, routeParams.provider, @@ -214,6 +215,7 @@ const CourseDetailsPage: FC<{}> = () => { progress={progress} progressReady={progressReady} profile={profile} + setCertificateProgress={setCertificateProgress} /> diff --git a/src-ts/tools/learn/course-details/course-curriculum/CourseCurriculum.tsx b/src-ts/tools/learn/course-details/course-curriculum/CourseCurriculum.tsx index 1b8e80b6a..408c65466 100644 --- a/src-ts/tools/learn/course-details/course-curriculum/CourseCurriculum.tsx +++ b/src-ts/tools/learn/course-details/course-curriculum/CourseCurriculum.tsx @@ -31,6 +31,7 @@ interface CourseCurriculumProps { profile?: UserProfile progress?: LearnUserCertificationProgress progressReady?: boolean + setCertificateProgress: (d: LearnUserCertificationProgress) => void } const CourseCurriculum: FC = (props: CourseCurriculumProps) => { @@ -108,7 +109,7 @@ const CourseCurriculum: FC = (props: CourseCurriculumProp } if (!props.progress?.id) { - await userCertificationProgressStartAsync( + const progress: LearnUserCertificationProgress = await userCertificationProgressStartAsync( props.profile.userId, props.course.certificationId, props.course.id, @@ -117,6 +118,9 @@ const CourseCurriculum: FC = (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, diff --git a/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx b/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx index 33829d44c..47f360465 100644 --- a/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx +++ b/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx @@ -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<{}> = () => { @@ -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, @@ -239,7 +240,7 @@ const FreeCodeCamp: FC<{}> = () => { }) // eslint-disable-next-line react-hooks/exhaustive-deps - }, [ + }, 30), [ certificateProgress, lessonParam, moduleParam, @@ -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, @@ -326,7 +327,7 @@ const FreeCodeCamp: FC<{}> = () => { navigate(nextLessonPath) // eslint-disable-next-line react-hooks/exhaustive-deps - }, [ + }, 30), [ certificateProgress, certificationParam, courseData?.modules, diff --git a/src-ts/tools/learn/learn-lib/data-providers/user-certifications-provider/user-certification-progress.provider.tsx b/src-ts/tools/learn/learn-lib/data-providers/user-certifications-provider/user-certification-progress.provider.tsx index 7bffd5039..9909a3a1c 100644 --- a/src-ts/tools/learn/learn-lib/data-providers/user-certifications-provider/user-certification-progress.provider.tsx +++ b/src-ts/tools/learn/learn-lib/data-providers/user-certifications-provider/user-certification-progress.provider.tsx @@ -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]), }