From fe608e4ac3ed29da28db7ce70068b7d7f49540cd Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Thu, 8 Dec 2022 17:10:40 +0200 Subject: [PATCH 1/4] Use progress.status to check certification completion status --- src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx b/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx index 33829d44c..d860f092c 100644 --- a/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx +++ b/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx @@ -287,7 +287,7 @@ const FreeCodeCamp: FC<{}> = () => { } // course is completed, return user to course completed screen - if (certificateProgress.courseProgressPercentage === 100) { + if (certificateProgress.status === UserCertificationProgressStatus.completed) { const completedPath: string = getCertificationCompletedPath( providerParam, certificationParam, From 70d01164f9f290fee5beff3ee91bbcf4fdc38aed Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Thu, 8 Dec 2022 17:11:08 +0200 Subject: [PATCH 2/4] user-certification-progress.ready - convert to boolean --- .../user-certification-progress.provider.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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]), } From 96367c809ab219404f6c17abe31e3c4b39c1f2f9 Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Thu, 8 Dec 2022 17:12:47 +0200 Subject: [PATCH 3/4] debounce lessonCompleted & lastLesson events from FCC --- src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx b/src-ts/tools/learn/free-code-camp/FreeCodeCamp.tsx index d860f092c..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,7 +281,7 @@ 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 @@ -326,7 +327,7 @@ const FreeCodeCamp: FC<{}> = () => { navigate(nextLessonPath) // eslint-disable-next-line react-hooks/exhaustive-deps - }, [ + }, 30), [ certificateProgress, certificationParam, courseData?.modules, From 5436a5a4ecce183aee1ffd8269ab38164a7633b9 Mon Sep 17 00:00:00 2001 From: Vasilica Olariu Date: Thu, 8 Dec 2022 17:15:15 +0200 Subject: [PATCH 4/4] When user starts a new course, call swr.mutate with the new certificationProgress data. --- src-ts/tools/learn/course-details/CourseDetailsPage.tsx | 2 ++ .../course-details/course-curriculum/CourseCurriculum.tsx | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) 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,