@@ -5,46 +5,42 @@ import PropTypes from 'prop-types';
5
5
import { useTranslation } from 'react-i18next' ;
6
6
import { Link , useLocation } from 'react-router-dom' ;
7
7
8
- /**
9
- * @description Secondary navigation component for the CleanAir site
10
- * @param {Array } disabledTabs
11
- * @returns {JSX.Element }
12
- */
13
8
const SecondaryNavComponent = ( { disabledTabs } ) => {
14
9
const { t } = useTranslation ( ) ;
15
10
const activeTab = useSelector ( ( state ) => state . cleanAirData . activeTab ) ;
16
11
const tabs = [
17
- t ( 'cleanAirSite.subNav.about' ) ,
18
- t ( 'cleanAirSite.subNav.membership' ) ,
19
- t ( 'cleanAirSite.subNav.events' ) ,
20
- t ( 'cleanAirSite.subNav.resources' )
12
+ { label : t ( 'cleanAirSite.subNav.about' ) , linkName : 'about' } ,
13
+ { label : t ( 'cleanAirSite.subNav.membership' ) , linkName : 'membership' } ,
14
+ { label : t ( 'cleanAirSite.subNav.events' ) , linkName : 'events' } ,
15
+ { label : t ( 'cleanAirSite.subNav.resources' ) , linkName : 'resources' }
21
16
] ;
17
+
22
18
const dispatch = useDispatch ( ) ;
23
19
const location = useLocation ( ) ;
24
-
25
20
useEffect ( ( ) => {
26
- dispatch ( setActiveTab ( tabs [ 0 ] ) ) ;
27
- const currentTab = tabs . findIndex ( ( tab ) => location . pathname . includes ( tab . toLowerCase ( ) ) ) ;
21
+ const currentTab = tabs . findIndex ( ( tab ) => location . pathname . includes ( tab . linkName ) ) ;
28
22
if ( currentTab !== - 1 && ! disabledTabs . includes ( currentTab ) ) {
29
23
dispatch ( setActiveTab ( tabs [ currentTab ] ) ) ;
30
24
}
31
- } , [ location , dispatch , tabs , disabledTabs ] ) ;
25
+ } , [ location ] ) ; // Only re-run the effect if location changes
32
26
33
27
return (
34
28
< div className = "header-subnav" >
35
29
< ul className = "tabs" >
36
30
{ tabs . map ( ( tab , index ) => (
37
- < Link to = { `/clean-air/${ tab . toLowerCase ( ) } ` } key = { index } >
31
+ < Link to = { `/clean-air/${ tab . linkName } ` } key = { index } >
38
32
< li
39
33
className = { `${
40
- location . pathname . includes ( tab . toLowerCase ( ) ) || activeTab === tab ? 'active' : ''
34
+ location . pathname . includes ( tab . linkName ) || activeTab . linkName === tab . linkName
35
+ ? 'active'
36
+ : ''
41
37
} ${ disabledTabs . includes ( index ) ? 'disabled' : '' } `}
42
38
onClick = { ( ) => {
43
39
if ( ! disabledTabs . includes ( index ) ) {
44
40
dispatch ( setActiveTab ( tab ) ) ;
45
41
}
46
42
} } >
47
- < span > { tab } </ span >
43
+ < span > { tab . label } </ span >
48
44
</ li >
49
45
</ Link >
50
46
) ) }
0 commit comments