Skip to content

Commit d915f84

Browse files
Update index.js
1 parent 53a5ff8 commit d915f84

File tree

1 file changed

+12
-16
lines changed
  • website/frontend/src/components/CleanAir/SecondaryNav

1 file changed

+12
-16
lines changed

website/frontend/src/components/CleanAir/SecondaryNav/index.js

+12-16
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,42 @@ import PropTypes from 'prop-types';
55
import { useTranslation } from 'react-i18next';
66
import { Link, useLocation } from 'react-router-dom';
77

8-
/**
9-
* @description Secondary navigation component for the CleanAir site
10-
* @param {Array} disabledTabs
11-
* @returns {JSX.Element}
12-
*/
138
const SecondaryNavComponent = ({ disabledTabs }) => {
149
const { t } = useTranslation();
1510
const activeTab = useSelector((state) => state.cleanAirData.activeTab);
1611
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' }
2116
];
17+
2218
const dispatch = useDispatch();
2319
const location = useLocation();
24-
2520
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));
2822
if (currentTab !== -1 && !disabledTabs.includes(currentTab)) {
2923
dispatch(setActiveTab(tabs[currentTab]));
3024
}
31-
}, [location, dispatch, tabs, disabledTabs]);
25+
}, [location]); // Only re-run the effect if location changes
3226

3327
return (
3428
<div className="header-subnav">
3529
<ul className="tabs">
3630
{tabs.map((tab, index) => (
37-
<Link to={`/clean-air/${tab.toLowerCase()}`} key={index}>
31+
<Link to={`/clean-air/${tab.linkName}`} key={index}>
3832
<li
3933
className={`${
40-
location.pathname.includes(tab.toLowerCase()) || activeTab === tab ? 'active' : ''
34+
location.pathname.includes(tab.linkName) || activeTab.linkName === tab.linkName
35+
? 'active'
36+
: ''
4137
} ${disabledTabs.includes(index) ? 'disabled' : ''}`}
4238
onClick={() => {
4339
if (!disabledTabs.includes(index)) {
4440
dispatch(setActiveTab(tab));
4541
}
4642
}}>
47-
<span>{tab}</span>
43+
<span>{tab.label}</span>
4844
</li>
4945
</Link>
5046
))}

0 commit comments

Comments
 (0)