// DashboardNavigation.js
import { useContext, useEffect, useState, useMemo } from 'react'
import {
Menu,
Flex,
Tag,
Space,
Dropdown,
Button,
Tooltip,
Badge,
Divider,
Typography
} from 'antd'
import {
LogoutOutlined,
MailOutlined,
LoadingOutlined
} from '@ant-design/icons'
import { AuthContext } from '../context/AuthContext'
import { SpotlightContext } from '../context/SpotlightContext'
import { ApiServerContext } from '../context/ApiServerContext'
import { useNavigate, useLocation } from 'react-router-dom'
import { Header } from 'antd/es/layout/layout'
import { useMediaQuery } from 'react-responsive'
import KeyboardShortcut from './KeyboardShortcut'
import FarmControlLogo from '../../Logos/FarmControlLogo'
import FarmControlLogoSmall from '../../Logos/FarmControlLogoSmall'
import MenuIcon from '../../Icons/MenuIcon'
import ProductionIcon from '../../Icons/ProductionIcon'
import InventoryIcon from '../../Icons/InventoryIcon'
import FinanceIcon from '../../Icons/FinanceIcon'
import SalesIcon from '../../Icons/SalesIcon'
import PersonIcon from '../../Icons/PersonIcon'
import CloudIcon from '../../Icons/CloudIcon'
import BellIcon from '../../Icons/BellIcon'
import SearchIcon from '../../Icons/SearchIcon'
import SettingsIcon from '../../Icons/SettingsIcon'
import DeveloperIcon from '../../Icons/DeveloperIcon'
import { ElectronContext } from '../context/ElectronContext'
import DashboardWindowButtons from './DashboardWindowButtons'
const { Text } = Typography
const DashboardNavigation = () => {
const { logout, userProfile } = useContext(AuthContext)
const { showSpotlight } = useContext(SpotlightContext)
const { toggleNotificationCenter, unreadCount } = useContext(ApiServerContext)
const { connecting, connected } = useContext(ApiServerContext)
const [apiServerState, setApiServerState] = useState('disconnected')
const navigate = useNavigate()
const location = useLocation()
const [selectedKey, setSelectedKey] = useState('production')
const [selectedMenuItem, setSelectedMenuItem] = useState({
key: 'production',
label: 'Production',
icon:
})
const isMobile = useMediaQuery({ maxWidth: 768 })
const { platform, isElectron, isFullScreen } = useContext(ElectronContext)
const mainMenuItems = useMemo(
() => [
{
key: 'production',
label: 'Production',
icon:
},
{
key: 'inventory',
label: 'Inventory',
icon:
},
{
key: 'sales',
label: 'Sales',
icon:
},
{
key: 'finance',
label: 'Finance',
icon:
},
{
key: 'management',
label: 'Management',
icon:
}
],
[]
)
const userMenuItems = {
items: [
{
key: 'username',
label: userProfile?.username,
icon: ,
disabled: true
},
{
key: 'email',
label: userProfile?.email,
icon: ,
disabled: true
},
{
key: 'logout',
label: 'Logout',
icon:
}
],
onClick: (key) => {
if (key === 'profile') {
navigate('/profile')
} else if (key === 'logout') {
logout()
}
}
}
useEffect(() => {
const pathParts = location.pathname.split('/').filter(Boolean)
if (pathParts.length > 2) {
setSelectedMenuItem(
mainMenuItems.filter((item) => item.key == pathParts[1])[0]
)
setSelectedKey(pathParts[1]) // Return the section (production/management)
}
}, [location.pathname, mainMenuItems])
useEffect(() => {
if (connecting == true) {
setApiServerState('connecting')
} else if (connected == true) {
setApiServerState('connected')
} else {
setApiServerState('disconnected')
}
}, [connecting, connected])
const handleMainMenuClick = ({ key }) => {
if (key === 'production') {
navigate('/dashboard/production/overview')
} else if (key === 'inventory') {
navigate('/dashboard/inventory/overview')
} else if (key === 'finance') {
navigate('/dashboard/finance/overview')
} else if (key === 'sales') {
navigate('/dashboard/sales/overview')
} else if (key === 'management') {
navigate('/dashboard/management/filaments')
}
}
const showAppLogo =
(isElectron && platform == 'darwin' && isFullScreen == true) ||
(isElectron && platform != 'darwin')
const isMacOSApp = isElectron && platform == 'darwin'
const isOtherApp = isElectron && platform != 'darwin'
const showDesktopLogo = !isElectron && !isMobile
const showMobileLogo = !isElectron && isMobile
const navigationContents = (
{isMacOSApp ? : null}
{showAppLogo == true && (
)}
{showDesktopLogo == true ? (
) : showMobileLogo == true ? (
) : null}
{isMobile && (
{selectedMenuItem.icon}
{selectedMenuItem.label}
)}
}
style={{ marginBottom: '4px' }}
/>
}
/>
{isMobile && }
showSpotlight()}
>
}
type='text'
style={{ marginTop: '2px' }}
onClick={() => showSpotlight()}
/>
toggleNotificationCenter()}
>
}
type='text'
style={{ marginTop: '2px' }}
onClick={() => toggleNotificationCenter()}
/>
{import.meta.env.MODE === 'development' && (
{apiServerState === 'connected' ? (
}
/>
) : null}
{apiServerState === 'connecting' ? (
}
/>
) : null}
{apiServerState === 'disconnected' ? (
}
/>
) : null}
}
onClick={() => {
navigate('/dashboard/developer/sessionstorage')
}}
/>
)}
{userProfile ? (
}>
{!isMobile && (userProfile?.name || userProfile.username)}
) : null}
{isOtherApp ? : null}
)
return (
<>
{isElectron ? (
{navigationContents}
) : (
)}
>
)
}
export default DashboardNavigation