1+ import { orderBy } from 'lodash'
12import { FC , ReactNode , useMemo } from 'react'
23
34import { Button } from '../../../../../lib'
45import {
56 LearnCertification ,
6- LearningHat ,
7+ LearnUserCertificationProgress ,
78 MyCourseCompletedCard ,
89 MyCourseInProgressCard ,
910 UserCertificationCompleted ,
1011 UserCertificationInProgress ,
12+ UserCertificationProgressStatus ,
1113} from '../../../learn-lib'
1214import { LEARN_PATHS } from '../../../learn.routes'
15+ import { CardsSlider } from '../cards-slider'
1316
1417import styles from './ProgressAction.module.scss'
1518
@@ -19,6 +22,12 @@ interface ProgressActionProps {
1922 userInProgressCertifications : ReadonlyArray < UserCertificationInProgress >
2023}
2124
25+ function isCompleted ( cert : LearnUserCertificationProgress ) : boolean {
26+ return cert . status === UserCertificationProgressStatus . completed
27+ }
28+
29+ const USER_PROGRESS_MAX_SLIDES_COUNT : number = 8
30+
2231const ProgressAction : FC < ProgressActionProps > = ( props : ProgressActionProps ) => {
2332
2433 const {
@@ -45,72 +54,56 @@ const ProgressAction: FC<ProgressActionProps> = (props: ProgressActionProps) =>
4554 } , { } as unknown as { [ key : string ] : LearnCertification } )
4655 ) , [ allCertifications ] )
4756
48- // we only want to display the last course that was acted upon
49- const mostRecentIsCompleted : boolean = myCompletedCertifications ?. [ 0 ] ?. updatedAt > ( myInProgressCertifications ?. [ 0 ] ?. updatedAt || 0 )
50-
51- function renderInProgress ( ) : JSX . Element {
52-
53- // if the most recently acted upon course is completed and not in progress,
54- // or there are no courses in progress, don't show this block
55- if ( mostRecentIsCompleted || ! myInProgressCertifications . length ) {
56- return < > </ >
57- }
58-
59- const courseToDisplay : UserCertificationInProgress = myInProgressCertifications [ 0 ]
57+ const recentlyUpdatedCertifications : Array < LearnUserCertificationProgress > = orderBy ( [
58+ ...myCompletedCertifications ,
59+ ...myInProgressCertifications ,
60+ ] , 'updatedAt' , 'desc' ) . slice ( 0 , USER_PROGRESS_MAX_SLIDES_COUNT )
6061
62+ function renderInProgress ( courseToDisplay : UserCertificationInProgress ) : JSX . Element {
6163 return (
62- < >
63- < div className = { styles [ 'title-line' ] } >
64- < h4 className = 'details' > In progress</ h4 >
65- < span className = 'mobile-hide' >
66- { allMyLearningsLink }
67- </ span >
68- </ div >
69- < MyCourseInProgressCard
70- certification = { certificationsById [ courseToDisplay . certificationId ] }
71- key = { courseToDisplay . certificationId }
72- completedPercentage = { courseToDisplay . courseProgressPercentage / 100 }
73- theme = 'minimum'
74- currentLesson = { courseToDisplay . currentLesson }
75- />
76- </ >
64+ < MyCourseInProgressCard
65+ certification = { certificationsById [ courseToDisplay . certificationId ] }
66+ key = { courseToDisplay . certificationId }
67+ completedPercentage = { courseToDisplay . courseProgressPercentage / 100 }
68+ theme = 'minimum'
69+ currentLesson = { courseToDisplay . currentLesson }
70+ />
7771 )
7872 }
7973
80- function renderCompleted ( ) : JSX . Element {
74+ function renderCompleted ( certToDisplay : UserCertificationCompleted ) : JSX . Element {
75+ return (
76+ < MyCourseCompletedCard
77+ certification = { certificationsById [ certToDisplay . certificationId ] }
78+ key = { certToDisplay . certificationId }
79+ completed = { certToDisplay . completedDate }
80+ />
81+ )
82+ }
8183
82- // if the most recently acted upon course is in progress rather than completed,
83- // or there are no completed courses, don't show this block
84- if ( ! mostRecentIsCompleted || ! myCompletedCertifications . length ) {
85- return < > </ >
84+ function renderCertificateCards ( ) : Array < JSX . Element > {
85+ if ( ! recentlyUpdatedCertifications . length ) {
86+ return [ ]
8687 }
8788
88- const certToDisplay : UserCertificationCompleted = myCompletedCertifications [ 0 ]
89-
90- return (
91- < >
92- < div className = { styles [ 'title-line' ] } >
93- < div className = { styles . title } >
94- < LearningHat />
95- < h4 className = 'details' > Congratulations!</ h4 >
96- </ div >
97- < span className = 'mobile-hide' >
98- { allMyLearningsLink }
99- </ span >
100- </ div >
101- < MyCourseCompletedCard
102- certification = { certificationsById [ certToDisplay . certificationId ] }
103- key = { certToDisplay . certificationId }
104- completed = { certToDisplay . completedDate }
105- />
106- </ >
107- )
89+ return recentlyUpdatedCertifications . map ( ( cert ) => (
90+ isCompleted ( cert )
91+ ? renderCompleted ( cert as UserCertificationCompleted )
92+ : renderInProgress ( cert as UserCertificationInProgress )
93+ ) )
10894 }
10995
11096 return (
11197 < >
112- { renderInProgress ( ) }
113- { renderCompleted ( ) }
98+ < div className = { styles [ 'title-line' ] } >
99+ < h4 className = 'details' > My progress</ h4 >
100+ < span className = 'mobile-hide' >
101+ { allMyLearningsLink }
102+ </ span >
103+ </ div >
104+ < CardsSlider >
105+ { renderCertificateCards ( ) }
106+ </ CardsSlider >
114107 < span className = 'desktop-hide' >
115108 { allMyLearningsLink }
116109 </ span >
0 commit comments