From 27e843e18360a92f7cbc2602afb7553c37dc98f1 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Mon, 18 Aug 2025 01:00:40 +0100 Subject: [PATCH] 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. --- .../Dashboard/common/DashboardNavigation.jsx | 52 +++---------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/src/components/Dashboard/common/DashboardNavigation.jsx b/src/components/Dashboard/common/DashboardNavigation.jsx index fa01e3c..e9739f2 100644 --- a/src/components/Dashboard/common/DashboardNavigation.jsx +++ b/src/components/Dashboard/common/DashboardNavigation.jsx @@ -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' && ( - {printServerState === 'connected' ? ( - - } - /> - - ) : null} - {printServerState === 'connecting' ? ( - - } - /> - - ) : null} - {printServerState === 'disconnected' ? ( - - } - /> - - ) : null} {apiServerState === 'connected' ? ( { {apiServerState === 'connecting' ? ( } />