Refactor DashboardNavigation to streamline API server state management

- Removed unused PrintServerContext and related print server state management.
- Updated API server state handling to use a single context for connection status.
- Improved code readability by consolidating state checks and simplifying the rendering logic for connection status indicators.
This commit is contained in:
Tom Butcher 2025-08-18 01:00:40 +01:00
parent df1115022a
commit 27e843e183

View File

@ -18,7 +18,6 @@ import {
LoadingOutlined LoadingOutlined
} from '@ant-design/icons' } from '@ant-design/icons'
import { AuthContext } from '../context/AuthContext' import { AuthContext } from '../context/AuthContext'
import { PrintServerContext } from '../context/PrintServerContext'
import { SpotlightContext } from '../context/SpotlightContext' import { SpotlightContext } from '../context/SpotlightContext'
import { ApiServerContext } from '../context/ApiServerContext' import { ApiServerContext } from '../context/ApiServerContext'
import { useNavigate, useLocation } from 'react-router-dom' import { useNavigate, useLocation } from 'react-router-dom'
@ -36,7 +35,6 @@ import BellIcon from '../../Icons/BellIcon'
import SearchIcon from '../../Icons/SearchIcon' import SearchIcon from '../../Icons/SearchIcon'
import SettingsIcon from '../../Icons/SettingsIcon' import SettingsIcon from '../../Icons/SettingsIcon'
import DeveloperIcon from '../../Icons/DeveloperIcon' import DeveloperIcon from '../../Icons/DeveloperIcon'
import PrinterIcon from '../../Icons/PrinterIcon'
import { ElectronContext } from '../context/ElectronContext' import { ElectronContext } from '../context/ElectronContext'
import DashboardWindowButtons from './DashboardWindowButtons' import DashboardWindowButtons from './DashboardWindowButtons'
@ -44,9 +42,7 @@ const DashboardNavigation = () => {
const { logout, userProfile } = useContext(AuthContext) const { logout, userProfile } = useContext(AuthContext)
const { showSpotlight } = useContext(SpotlightContext) const { showSpotlight } = useContext(SpotlightContext)
const { toggleNotificationCenter, unreadCount } = useContext(ApiServerContext) const { toggleNotificationCenter, unreadCount } = useContext(ApiServerContext)
const { printServer } = useContext(PrintServerContext) const { connecting, connected } = useContext(ApiServerContext)
const { apiServer } = useContext(ApiServerContext)
const [printServerState, setPrintServerState] = useState('disconnected')
const [apiServerState, setApiServerState] = useState('disconnected') const [apiServerState, setApiServerState] = useState('disconnected')
const navigate = useNavigate() const navigate = useNavigate()
const location = useLocation() const location = useLocation()
@ -62,24 +58,15 @@ const DashboardNavigation = () => {
}, [location.pathname]) }, [location.pathname])
useEffect(() => { useEffect(() => {
if (printServer?.connecting) { if (connecting == true) {
setPrintServerState('connecting')
} else if (printServer?.connected) {
setPrintServerState('connected')
} else {
setPrintServerState('disconnected')
}
}, [printServer?.connecting, printServer?.connected])
useEffect(() => {
if (apiServer?.connecting) {
setApiServerState('connecting') setApiServerState('connecting')
} else if (apiServer?.connected) { } else if (connected == true) {
setApiServerState('connected') setApiServerState('connected')
} else { } else {
setApiServerState('disconnected') setApiServerState('disconnected')
} }
}, [apiServer?.connecting, apiServer?.connected]) console.log('Connecting/connected', connecting, connected)
}, [connecting, connected])
const mainMenuItems = [ const mainMenuItems = [
{ {
@ -191,33 +178,6 @@ const DashboardNavigation = () => {
{process.env.NODE_ENV === 'development' && ( {process.env.NODE_ENV === 'development' && (
<Space> <Space>
{printServerState === 'connected' ? (
<Tooltip title='Connected to print server' arrow={false}>
<Tag
color='success'
style={{ marginRight: 0 }}
icon={<PrinterIcon />}
/>
</Tooltip>
) : null}
{printServerState === 'connecting' ? (
<Tooltip title='Connecting to print erver...' arrow={false}>
<Tag
color='default'
style={{ marginRight: 0 }}
icon={<LoadingOutlined />}
/>
</Tooltip>
) : null}
{printServerState === 'disconnected' ? (
<Tooltip title='Disconnected from print server' arrow={false}>
<Tag
color='error'
style={{ marginRight: 0 }}
icon={<PrinterIcon />}
/>
</Tooltip>
) : null}
{apiServerState === 'connected' ? ( {apiServerState === 'connected' ? (
<Tooltip title='Connected to api server' arrow={false}> <Tooltip title='Connected to api server' arrow={false}>
<Tag <Tag
@ -230,7 +190,7 @@ const DashboardNavigation = () => {
{apiServerState === 'connecting' ? ( {apiServerState === 'connecting' ? (
<Tooltip title='Connecting to api erver...' arrow={false}> <Tooltip title='Connecting to api erver...' arrow={false}>
<Tag <Tag
color='default' color='warning'
style={{ marginRight: 0 }} style={{ marginRight: 0 }}
icon={<LoadingOutlined />} icon={<LoadingOutlined />}
/> />