generated from agiledev-students-fall2023/generic-project-repository
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from agiledev-students-fall2023/minor-improvem…
…ents-1 Various Minor Improvements
- Loading branch information
Showing
4 changed files
with
165 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,90 @@ | ||
import '../css/navBar.css' | ||
import '../css/navBar.css'; | ||
import { ReactComponent as MapIcon } from '../images/map.svg'; | ||
import { ReactComponent as AlertIcon } from '../images/alert.svg'; | ||
import { ReactComponent as RouteIcon } from '../images/route.svg'; | ||
import { ReactComponent as SettingIcon } from '../images/gears.svg'; | ||
import { useState, useEffect , useContext } from 'react'; | ||
import { useState, useEffect, useContext } from 'react'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { TutorialContext } from '../App'; | ||
import '../css/tutorialComponent.css' | ||
import '../css/tutorialComponent.css'; | ||
import TutorialComponent from './TutorialComponent'; | ||
|
||
function NavBar() { | ||
const [navBarState, setNavBarState] = useState('Map'); | ||
const {tutorialIndex, setTutorialIndex, firstTime, setFirstTime, tutorialOn, setTutorialOn} = useContext(TutorialContext); | ||
const navigate = useNavigate(); | ||
const handleClick = (iconName) => { | ||
setNavBarState(iconName); | ||
} | ||
|
||
useEffect(() => { | ||
let overlay = document.getElementsByClassName('overlay')[0]; | ||
let cur = document.getElementById(navBarState); | ||
if (cur.classList.contains('inactive')) { // when a inactive icon is clicked | ||
document.getElementsByClassName('active')[0].classList.add('inactive'); | ||
document.getElementsByClassName('active')[0].classList.remove('active'); | ||
cur.classList.remove('inactive'); | ||
cur.classList.add('active'); | ||
switch(navBarState) { //change the functionalities of each button here | ||
case 'Map': | ||
overlay.style.left = '-36%'; //shifts the overlay | ||
navigate('/map') | ||
break; | ||
case 'Routes': | ||
overlay.style.left = '-12%'; | ||
navigate('/routes') | ||
break; | ||
case 'Alerts': | ||
overlay.style.left = '12%'; | ||
navigate('/alerts') | ||
break; | ||
case 'Settings': | ||
overlay.style.left = '36%'; | ||
navigate('/settings') | ||
break; | ||
} | ||
} | ||
}, [navBarState]); | ||
const getPath = () => window.location.pathname.split('/')[1] || 'map'; | ||
const [navigationState, setnavigationState] = useState(getPath()); | ||
const { tutorialIndex, setTutorialIndex, firstTime, setFirstTime, tutorialOn, setTutorialOn } = | ||
useContext(TutorialContext); | ||
const navigate = useNavigate(); | ||
const handleClick = (iconName) => { | ||
setnavigationState(iconName); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="navBar"> | ||
<div className="backdrop"></div> | ||
<div className="overlay"></div> | ||
<div className="active" id="Map" onClick={() => handleClick('Map')}> | ||
<MapIcon fill='#F0E9FF' width="25" height="25" aria-label="Map" /> | ||
<p>Map</p> | ||
</div> | ||
<div className="inactive" id="Routes" onClick={() => handleClick('Routes')}> | ||
<RouteIcon width="25" height="25" aria-label="Routes" /> | ||
<p>Routes</p> | ||
</div> | ||
<div className="inactive" id="Alerts" onClick={() => handleClick('Alerts')}> | ||
<AlertIcon width="25" height="25" aria-label="Alerts" /> | ||
<p className="flex">Alerts</p> | ||
</div> | ||
<div className="inactive" id="Settings" onClick={() => handleClick('Settings')}> | ||
<SettingIcon width="25" height="25" aria-label="Settings" /> | ||
<p>Settings</p> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
const updateNavBarDisplay = (to) => { | ||
const overlay = document.getElementsByClassName('overlay')[0]; | ||
const cur = document.getElementById(to); | ||
if (cur.classList.contains('inactive')) { | ||
// when a inactive icon is clicked | ||
document.getElementsByClassName('active')[0].classList.add('inactive'); | ||
document.getElementsByClassName('active')[0].classList.remove('active'); | ||
cur.classList.remove('inactive'); | ||
cur.classList.add('active'); | ||
|
||
//change the functionalities of each button here | ||
switch (to) { | ||
case 'map': | ||
overlay.style.left = '-36%'; //shifts the overlay | ||
break; | ||
case 'routes': | ||
overlay.style.left = '-12%'; | ||
break; | ||
case 'alerts': | ||
overlay.style.left = '12%'; | ||
break; | ||
case 'settings': | ||
overlay.style.left = '36%'; | ||
break; | ||
} | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
updateNavBarDisplay(navigationState); | ||
if (navigationState !== getPath()) { | ||
navigate('/' + navigationState); | ||
} | ||
}, [navigationState]); | ||
|
||
useEffect(() => { | ||
// Send first time users to the map page | ||
if (localStorage.getItem('isFirst') !== 'true') { | ||
setnavigationState('map'); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<div className="navBar"> | ||
<div className="backdrop"></div> | ||
<div className="overlay"></div> | ||
<div className="active" id="map" onClick={() => handleClick('map')}> | ||
<MapIcon fill="#F0E9FF" width="25" height="25" aria-label="Map" /> | ||
<p>Map</p> | ||
</div> | ||
<div className="inactive" id="routes" onClick={() => handleClick('routes')}> | ||
<RouteIcon width="25" height="25" aria-label="Routes" /> | ||
<p>Routes</p> | ||
</div> | ||
<div className="inactive" id="alerts" onClick={() => handleClick('alerts')}> | ||
<AlertIcon width="25" height="25" aria-label="Alerts" /> | ||
<p className="flex">Alerts</p> | ||
</div> | ||
<div className="inactive" id="settings" onClick={() => handleClick('settings')}> | ||
<SettingIcon width="25" height="25" aria-label="Settings" /> | ||
<p>Settings</p> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
export default NavBar; | ||
export default NavBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.