import { Capacitor } from '@capacitor/core'
import {
Archive,
ArrowBack,
FilterAlt,
FolderOpen,
History,
Inbox,
ListAlt,
Logout,
MenuRounded,
SettingsOutlined,
Toll,
Widgets,
} from '@mui/icons-material'
import {
Box,
Drawer,
IconButton,
List,
ListItemButton,
ListItemContent,
ListItemDecorator,
Typography,
} from '@mui/joy'
import { useEffect, 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 { useLocalization } from '../../contexts/LocalizationContext'
import NavBarLink from './NavBarLink'
import { SafeArea } from 'capacitor-plugin-safe-area'
import Z_INDEX from '../../constants/zIndex'
import { useResource } from '../../queries/ResourceQueries'
import { apiClient } from '../../utils/ApiClient'
const publicPages = ['/landing', '/privacy', '/terms']
const NavBar = () => {
const { t } = useTranslation('common')
const { isRTL } = useLocalization()
const { data: resource } = useResource()
const navigate = useNavigate()
const [drawerOpen, setDrawerOpen] = useState(false)
const links = [
{
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()
useEffect(() => {
SafeArea.getSafeAreaInsets().then(data => {
const { insets } = data
const drawerContent = document.querySelector('.drawer-content')
if (drawerContent) {
drawerContent.style.paddingTop = `${insets.top}px`
drawerContent.style.paddingRight = `${insets.right}px`
drawerContent.style.paddingBottom = `${insets.bottom}px`
drawerContent.style.paddingLeft = `${insets.left}px`
}
})
}, [])
const getMenuIcon = () => {
const menuRounded = (
setDrawerOpen(true)}>
)
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',
].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