@@ -5,34 +5,40 @@ import { Button, Avatar } from '@fluentui/react-components'
55import styles from './Sidebar.module.css'
66import { AppStateContext } from '../../state/AppProvider'
77import { getUserInfo } from '../../api'
8- import { useNavigate } from 'react-router-dom'
8+ import { useNavigate , useLocation } from 'react-router-dom'
99
1010interface NavigationButtonProps {
1111 text : string
12- icon : JSX . Element
12+ isActive : boolean
1313 onClick : ( ) => void
1414}
1515
16- const NavigationButton = ( { text, icon, onClick } : NavigationButtonProps ) => {
16+ const NavigationButton = ( { text, isActive, onClick } : NavigationButtonProps ) => {
17+ const fontColor = isActive ? '#367AF6' : '#BEBBB8'
18+ const iconElements : { [ key : string ] : JSX . Element } = {
19+ 'Browse' : < News28Regular color = { fontColor } /> ,
20+ 'Generate' : < Book28Regular color = { fontColor } /> ,
21+ 'Draft' : < Notepad28Regular color = { fontColor } />
22+ }
23+
24+ const icon = iconElements [ text ]
25+
1726 return (
18- < Stack
19- onClick = { onClick }
20- className = { styles . navigationButton }
21- >
22- < Button
23- appearance = "transparent"
24- size = "large"
25- icon = { icon }
26- style = { { padding : '0' } }
27+ < Stack onClick = { onClick } className = { isActive ? styles . navigationButtonActive : styles . navigationButton } >
28+ < Button appearance = "transparent"
29+ size = "large"
30+ icon = { icon }
31+ style = { { padding : '0' } }
2732 />
28- < p > { text } </ p >
33+ < Text style = { { color : fontColor } } > { text } </ Text >
2934 </ Stack >
3035 )
3136}
3237
3338const Sidebar = ( ) : JSX . Element => {
3439 const appStateContext = useContext ( AppStateContext )
3540 const navigate = useNavigate ( )
41+ const location = useLocation ( ) ;
3642 const [ name , setName ] = useState < string > ( "" )
3743
3844 useEffect ( ( ) => {
@@ -46,17 +52,28 @@ const Sidebar = (): JSX.Element => {
4652 console . error ( 'Error fetching user info: ' , err )
4753 } )
4854 }
49- } , [ ] )
55+ } , [ ] )
56+
57+ // determine url from react-router-dom
58+ const determineView = ( ) => {
59+ const url = location . pathname
60+
61+ const urlArr = url . split ( '/' )
62+ const currentUrl = urlArr [ urlArr . length - 1 ]
63+ return currentUrl
64+ }
65+
66+ const currentView = determineView ( )
5067
5168 return (
5269 < Stack className = { styles . sidebarContainer } >
5370 < Stack horizontal className = { styles . avatarContainer } >
5471 < Avatar color = "colorful" name = { name } />
5572 </ Stack >
5673 < Stack className = { styles . sidebarNavigationContainer } >
57- < NavigationButton text = { "Browse" } icon = { < News28Regular color = "#0078D4" /> } onClick = { ( ) => { navigate ( "/chat" ) } } />
58- < NavigationButton text = { "Generate" } icon = { < Book28Regular color = "#0078D4" /> } onClick = { ( ) => { navigate ( "/generate" ) } } />
59- < NavigationButton text = { "Draft" } icon = { < Notepad28Regular color = "#0078D4" /> } onClick = { ( ) => { navigate ( "/draft" ) } } />
74+ < NavigationButton text = { "Browse" } isActive = { currentView === 'chat' } onClick = { ( ) => { navigate ( "/chat" ) } } />
75+ < NavigationButton text = { "Generate" } isActive = { currentView === 'generate' } onClick = { ( ) => { navigate ( "/generate" ) } } />
76+ < NavigationButton text = { "Draft" } isActive = { currentView === 'draft' } onClick = { ( ) => { navigate ( "/draft" ) } } />
6077 </ Stack >
6178 </ Stack >
6279 )
0 commit comments