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