Skip to content
Snippets Groups Projects
Navbar.tsx 4.89 KiB
Newer Older
  • Learn to ignore specific revisions
  • import Link from '@material-ui/core/Link'
    
    import AnalysisIconOff from 'assets/icons/tabbar/analysis/analysis-off.svg'
    import AnalysisIconOn from 'assets/icons/tabbar/analysis/analysis-on.svg'
    import BulbIconOff from 'assets/icons/tabbar/astuces/astuces-off.svg'
    
    import BulbIconOn from 'assets/icons/tabbar/astuces/astuces-on.svg'
    
    import ConsoIconOff from 'assets/icons/tabbar/conso/conso-off.svg'
    import ConsoIconOn from 'assets/icons/tabbar/conso/conso-on.svg'
    
    import ChallengeIconOff from 'assets/icons/tabbar/defi/defi-off.svg'
    import ChallengeIconOn from 'assets/icons/tabbar/defi/defi-on.svg'
    
    CREY Romain's avatar
    CREY Romain committed
    import ParameterIconOff from 'assets/icons/tabbar/parametre/parametre-off.svg'
    
    import ParameterIconOn from 'assets/icons/tabbar/parametre/parametre-on.svg'
    
    import logos from 'assets/png/logos_partenaires.svg'
    
    CREY Romain's avatar
    CREY Romain committed
    import StyledIcon from 'components/CommonKit/Icon/StyledIcon'
    
    import { useClient } from 'cozy-client'
    import { useI18n } from 'cozy-ui/transpiled/react/I18n'
    
    import { UsageEventType } from 'enums'
    
    import React, { useCallback } from 'react'
    
    import { NavLink, useLocation } from 'react-router-dom'
    
    import UsageEventService from 'services/usageEvent.service'
    
    import { useAppSelector } from 'store/hooks'
    
    import './navBar.scss'
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
    
    
    const Navbar = () => {
    
      const { t } = useI18n()
    
      const {
        challengeExplorationNotification,
        challengeActionNotification,
        challengeDuelNotification,
        analysisNotification,
    
      } = useAppSelector(state => state.ecolyo.global)
    
      const { pathname } = useLocation()
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
    
    
      const client = useClient()
      const emitNavEvent = useCallback(
        async (targetPage: string) => {
          await UsageEventService.addEvent(client, {
            type: UsageEventType.NAVIGATION_EVENT,
            target: targetPage,
          })
        },
        [client]
      )
    
    
      /** Return class "is-active" if pathname includes matcher */
      const isActive = (matcher: string) => {
        return pathname.includes(matcher) ? 'is-active' : ''
      }
    
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
      return (
        <aside className="o-sidebar">
    
          <nav role="navigation" aria-label="navigation">
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
            <ul className="c-nav">
    
              <li
                className="c-nav-item"
                onClick={() => emitNavEvent('consumption')}
              >
    
                <Link
                  component={NavLink}
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
                  to="/consumption"
    
                  className={`c-nav-link ${isActive('/consumption')}`}
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
                >
    
    CREY Romain's avatar
    CREY Romain committed
                  <StyledIcon className="c-nav-icon off" icon={ConsoIconOff} />
                  <StyledIcon className="c-nav-icon on" icon={ConsoIconOn} />
    
    Yoan VALLET's avatar
    Yoan VALLET committed
                  {t('navigation.consumption')}
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
              </li>
    
              <li className="c-nav-item" onClick={() => emitNavEvent('challenges')}>
    
                <Link
                  component={NavLink}
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
                  to="/challenges"
    
                  className={`c-nav-link ${isActive('/challenges')}`}
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
                >
    
                  {(challengeExplorationNotification ||
                    challengeActionNotification ||
                    challengeDuelNotification) && <div className="nb-notif">1</div>}
    
    CREY Romain's avatar
    CREY Romain committed
                  <StyledIcon className="c-nav-icon off" icon={ChallengeIconOff} />
                  <StyledIcon className="c-nav-icon on" icon={ChallengeIconOn} />
    
    Yoan VALLET's avatar
    Yoan VALLET committed
                  {t('navigation.challenges')}
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
              </li>
    
              <li
                className="c-nav-item"
                onClick={() => emitNavEvent('ecogestures')}
              >
    
                <Link
                  component={NavLink}
    
                  to="/ecogestures"
    
                  className={`c-nav-link ${isActive('/ecogesture')}`}
    
                  <StyledIcon className="c-nav-icon off" icon={BulbIconOff} />
                  <StyledIcon className="c-nav-icon on" icon={BulbIconOn} />
    
    Yoan VALLET's avatar
    Yoan VALLET committed
                  {t('navigation.ecogestures')}
    
              <li className="c-nav-item" onClick={() => emitNavEvent('analysis')}>
    
                <Link
                  component={NavLink}
    
                  className={`c-nav-link ${
                    pathname === '/analysis' ? 'is-active' : ''
                  }`}
    
                  {analysisNotification && <div className="nb-notif">1</div>}
    
                  <StyledIcon className="c-nav-icon off" icon={AnalysisIconOff} />
                  <StyledIcon className="c-nav-icon on" icon={AnalysisIconOn} />
    
    Yoan VALLET's avatar
    Yoan VALLET committed
                  {t('navigation.analysis')}
    
    Yoan VALLET's avatar
    Yoan VALLET committed
              </li>
    
              <li className="c-nav-item" onClick={() => emitNavEvent('options')}>
    
                <Link
                  component={NavLink}
    
                  to="/options"
    
                  className={`c-nav-link ${isActive('/options')}`}
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
                >
    
    CREY Romain's avatar
    CREY Romain committed
                  <StyledIcon className="c-nav-icon off" icon={ParameterIconOff} />
                  <StyledIcon className="c-nav-icon on" icon={ParameterIconOn} />
    
    Yoan VALLET's avatar
    Yoan VALLET committed
                  {t('navigation.options')}
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
              </li>
            </ul>
          </nav>
    
          <div role="contentinfo" className="logos-container">
    
    HAUTBOIS Aurelie's avatar
    HAUTBOIS Aurelie committed
            <img src={logos} alt="ensemble de logos" />
    
    Guilhem CARRON's avatar
    Guilhem CARRON committed
          </div>
    
    Hugo NOUTS's avatar
    Hugo NOUTS committed
        </aside>
      )
    }
    
    
    export default Navbar