@@ -3,6 +3,7 @@ import Link from "next/link";
3
3
import { useRouter } from "next/router" ;
4
4
import { useTranslation } from "next-i18next" ;
5
5
import classNames from "classnames" ;
6
+ import { useMemo } from "react" ;
6
7
7
8
/**
8
9
* @interface SidebarProps
@@ -29,22 +30,33 @@ export default function Sidebar(): JSX.Element {
29
30
return router . asPath === link ;
30
31
} ;
31
32
32
- const scoreboardLink = hasCurrentCommunity ? `/communities/${ currentCommunity . slug } /scoreboard` : "" ;
33
- const learningMaterialsLink = hasCurrentCommunity ? `/communities/${ currentCommunity . slug } /learning-materials` : "" ;
34
- const mainLink = hasCurrentCommunity ? `/communities/${ currentCommunity . slug } ` : "" ;
33
+ const links = useMemo ( ( ) => {
34
+ if ( ! hasCurrentCommunity )
35
+ return {
36
+ scoreboardLink : "" ,
37
+ learningMaterialsLink : "" ,
38
+ mainLink : "" ,
39
+ } ;
40
+ const { slug } = currentCommunity ;
41
+ return {
42
+ scoreboardLink : `/communities/${ slug } /scoreboard` ,
43
+ learningMaterialsLink : `/communities/${ slug } /learning-materials` ,
44
+ mainLink : `/communities/${ slug } ` ,
45
+ } ;
46
+ } , [ hasCurrentCommunity , currentCommunity ] ) ;
35
47
36
48
return (
37
49
< div className = "flex flex-col md:divide-y divide-solid divide-gray-100 w-full text-gray-700 space-y-6" >
38
- < Link href = { mainLink } >
39
- < div className = { isActive ( mainLink ) ? "" : "text-tertiary" } >
50
+ < Link href = { links . mainLink } >
51
+ < div className = { isActive ( links . mainLink ) ? "" : "text-tertiary" } >
40
52
< div className = "font-medium text-.5xl leading-snug" > { t ( "communities.overview.challenges.title" ) } </ div >
41
53
< div className = "text-sm font-light lg:w-full lg:pr-7 pt-2 mb-6 md:mb-0" > { t ( "communities.overview.challenges.description" ) } </ div >
42
54
</ div >
43
55
</ Link >
44
- < Link href = { learningMaterialsLink } >
56
+ < Link href = { links . learningMaterialsLink } >
45
57
< div className = { classNames ( "pt-6" ,
46
58
{
47
- "text-tertiary" : ! isActive ( learningMaterialsLink ) ,
59
+ "text-tertiary" : ! isActive ( links . learningMaterialsLink ) ,
48
60
}
49
61
) }
50
62
>
@@ -53,11 +65,11 @@ export default function Sidebar(): JSX.Element {
53
65
</ div >
54
66
</ Link >
55
67
{ hasCurrentCommunity && (
56
- < Link href = { scoreboardLink } >
68
+ < Link href = { links . scoreboardLink } >
57
69
< div className = { classNames ( "pt-6" ,
58
70
{
59
- "md:block hidden scroll-smooth" : isActive ( scoreboardLink ) ,
60
- "text-tertiary" : ! isActive ( scoreboardLink )
71
+ "md:block hidden scroll-smooth" : isActive ( links . scoreboardLink ) ,
72
+ "text-tertiary" : ! isActive ( links . scoreboardLink )
61
73
} ,
62
74
) } >
63
75
< div className = "font-medium text-.5xl leading-snug" > { t ( "communities.overview.scoreboard.title" ) } </ div >
0 commit comments