// DashboardNavigation.js import { useContext, useEffect, useState, useMemo } from 'react' import { Menu, Flex, Tag, Space, Button, Tooltip, Badge, Divider, Typography, Popover } from 'antd' import { LoadingOutlined } from '@ant-design/icons' import { AuthContext } from '../context/AuthContext' import { SpotlightContext } from '../context/SpotlightContext' import { ApiServerContext } from '../context/ApiServerContext' import { NotificationContext } from '../context/NotificationContext' import { useNavigate, useLocation } from 'react-router-dom' import { Header } from 'antd/es/layout/layout' import { useMediaQuery } from 'react-responsive' import KeyboardShortcut from './KeyboardShortcut' import UserProfilePopover from './UserProfilePopover' 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' import WebAppSwitcher from './WebAppSwitcher' import { getSidebarDefaultPath, getSidebarMenuSections } from '../../../database/Sidebars' import { useAppUpdateContext } from '../context/AppUpdateContext' const { Text } = Typography const DashboardNavigation = () => { const { userProfile } = useContext(AuthContext) const { showSpotlight } = useContext(SpotlightContext) const { connecting, connected } = useContext(ApiServerContext) const { toggleNotificationCenter, unreadCount, notificationCenterVisible } = useContext(NotificationContext) 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, setSidebarViewMenu } = useContext(ElectronContext) const { availableUpdate, checkForUpdates } = useAppUpdateContext() 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 [userPopoverOpen, setUserPopoverOpen] = useState(false) const userPopoverContent = ( setUserPopoverOpen(false)} /> ) 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 }) => { navigate(getSidebarDefaultPath(key, { includeDev: import.meta.env.DEV })) } useEffect(() => { if (!isElectron || !setSidebarViewMenu) return const includeDev = import.meta.env.DEV const sections = getSidebarMenuSections({ includeDev }) setSidebarViewMenu(sections) }, [isElectron, setSidebarViewMenu]) 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()} >