import { Capacitor } from '@capacitor/core'
import {
Archive,
ArrowBack,
FilterAlt,
FolderOpen,
History,
Inbox,
ListAlt,
Logout,
MenuRounded,
SearchRounded,
SettingsOutlined,
Toll,
Widgets,
} from '@mui/icons-material'
import {
Box,
Drawer,
IconButton,
List,
ListItemButton,
ListItemContent,
ListItemDecorator,
Typography,
} from '@mui/joy'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'
import { version } from '../../../package.json'
import UserProfileAvatar from '../../components/UserProfileAvatar'
import Z_INDEX from '../../constants/zIndex'
import { useLocalization } from '../../contexts/LocalizationContext'
import { useResource } from '../../queries/ResourceQueries'
import { useGlobalSearch } from '../../search/GlobalSearchContext'
import { apiClient } from '../../utils/ApiClient'
import NavBarLink from './NavBarLink'
import SyncStatusIndicator from './SyncStatusIndicator'
const publicPages = ['/landing', '/privacy', '/terms']
const NavBar = () => {
const { t } = useTranslation('common')
const { isRTL } = useLocalization()
const { data: resource } = useResource()
const { openSearch } = useGlobalSearch()
const navigate = useNavigate()
const [drawerOpen, setDrawerOpen] = useState(false)
const links = [
{
label: t('navigation.search'),
icon: ,
onClick: () => openSearch(),
},
{
to: '/chores',
label: t('navigation.allTasks'),
icon: ,
},
{
to: '/archived',
label: t('navigation.archived'),
icon: ,
},
{
to: '/things',
label: t('navigation.things'),
icon: ,
},
{
to: 'labels',
label: t('navigation.labels'),
icon: ,
},
{
to: 'projects',
label: t('navigation.projects'),
icon: ,
},
{
to: 'filters',
label: t('navigation.filters'),
icon: ,
},
{
to: 'activities',
label: t('navigation.activities'),
icon: ,
},
{
to: 'points',
label: t('navigation.points'),
icon: ,
},
{
to: '/settings',
label: t('navigation.settings'),
icon: ,
},
]
const [openDrawer, closeDrawer] = [
() => setDrawerOpen(true),
() => setDrawerOpen(false),
]
const location = useLocation()
const [searchParams] = useSearchParams()
const getMenuIcon = () => {
const menuRounded = (
setDrawerOpen(true)}>
)
if (location.pathname === '/search') {
return (
{
if (window.history.state?.idx > 0) navigate(-1)
else navigate('/chores', { replace: true })
}}
aria-label='Back from search'
title={t('back')}
>
)
}
if (!Capacitor.isNativePlatform()) {
return menuRounded
}
if (
['/chores', '/'].includes(location.pathname) &&
!searchParams.get('filterId')
) {
return menuRounded
}
return (
{
if (location.pathname === '/chores') {
// Navigate back to calendar view
navigate('/')
} else {
// Default back navigation
navigate(-1)
}
}}
title={
searchParams.get('from') === 'calendar'
? t('backToCalendar')
: t('back')
}
>
)
}
if (
[
'/signup',
'/login',
'/auth/oauth2',
'/forgot-password',
'/password/update',
'/login/settings',
'/welcome',
'/onboarding',
'/get-started',
'/ready',
].includes(location.pathname)
) {
return (
// no navbar but show the safe area padding
)
}
// if url has /landing then remove the navbar:
if (publicPages.includes(location.pathname)) {
return null
}
if (
window.location.hostname === 'www.donetick.com' ||
window.location.hostname === 'donetick.com'
) {
return null
}
return (
)
}
export default NavBar