1
- import { Fragment , useEffect , useState } from "react" ;
1
+ import { Fragment , useMemo } from "react" ;
2
2
import ArrowButton from "@/components/ui/button/Arrow" ;
3
3
import Link from "next/link" ;
4
4
import { useTranslation } from "next-i18next" ;
@@ -16,18 +16,16 @@ import { LearningModule } from "@/types/course";
16
16
* Component that displays related learning material with a title, description, and "Start now" button.
17
17
*/
18
18
export function LearningModuleCard ( { data } : { data : LearningModule } ) : JSX . Element {
19
- const [ level , setLevel ] = useState ( "" ) ;
20
19
const { t } = useTranslation ( )
21
20
const { challenge, community, colors } = useMultiSelector < any , any > ( {
22
21
challenge : ( state : IRootState ) => state . challenges . current ,
23
22
community : ( state : IRootState ) => state . communities . current ,
24
23
colors : ( state : IRootState ) => state . ui . colors
25
24
} )
26
25
27
- useEffect ( ( ) => {
28
- if ( ! challenge ?. level ) return
29
- if ( challenge . level === 0 || challenge . level === 1 ) return setLevel ( "course.challenge.level-0" ) ;
30
- return setLevel ( "course.challenge.level-2" ) ;
26
+ const level = useMemo ( ( ) => {
27
+ const value = challenge ?. level ;
28
+ return t ( ( value === 0 || value === 1 ) ? "course.challenge.level-0" : "course.challenge.level-2" ) ;
31
29
} , [ challenge ?. level ] ) ;
32
30
33
31
const courses = data ?. courses . map ( course => ( { name : course . name , slug : course . slug } ) )
@@ -40,7 +38,7 @@ export function LearningModuleCard({ data }: { data: LearningModule }): JSX.Elem
40
38
< span className = "uppercase font-semibold" > { t ( "communities.card.module" ) } </ span >
41
39
</ div >
42
40
< div className = "gap-2 flex items-center" >
43
- < Tag className = "uppercase" > { t ( level ) } </ Tag >
41
+ { challenge . level && < Tag className = "uppercase" > { level } </ Tag > }
44
42
< DurationCard value = { data . duration } type = "bordered" />
45
43
</ div >
46
44
</ div >
0 commit comments