Add clear-plate dot indicator on sidebar Printers icon

When a printer has pending queue items and is in FINISH/FAILED state
awaiting plate clearing, a yellow dot now appears on the Printers
sidebar icon. Uses useQueries to check statuses of printers with
pending queue items from the existing WebSocket-warmed React Query
cache — no new backend endpoints or additional polling needed.
This commit is contained in:
maziggy
2026-02-23 08:13:29 +01:00
parent b66d7fdec0
commit 77677cb07f
6 changed files with 119 additions and 91 deletions
+28 -1
View File
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
import { useTheme } from '../contexts/ThemeContext';
import { KeyboardShortcutsModal } from './KeyboardShortcutsModal';
import { SwitchbarPopover } from './SwitchbarPopover';
import { useQuery } from '@tanstack/react-query';
import { useQuery, useQueries } from '@tanstack/react-query';
import { api, supportApi, pendingUploadsApi } from '../api/client';
import { getIconByName } from './IconPicker';
import { useIsSidebarCompact } from '../hooks/useIsSidebarCompact';
@@ -178,6 +178,29 @@ export function Layout() {
});
const pendingUploadsCount = pendingUploadsData?.count ?? 0;
// Check if any printer with pending queue items needs plate clearing
const queuePrinterIds = useMemo(() => {
const ids = new Set<number>();
queueItems?.forEach(item => {
if (item.printer_id) ids.add(item.printer_id);
});
return Array.from(ids);
}, [queueItems]);
const printerStatusQueries = useQueries({
queries: queuePrinterIds.map(id => ({
queryKey: ['printerStatus', id],
queryFn: () => api.getPrinterStatus(id),
staleTime: 30 * 1000, // WebSocket keeps this warm
})),
});
const needsClearPlate = printerStatusQueries.some(result => {
const status = result.data;
if (!status) return false;
return (status.state === 'FINISH' || status.state === 'FAILED') && !status.plate_cleared;
});
// Calculate debug duration client-side for real-time updates
const [debugDuration, setDebugDuration] = useState<number | null>(null);
useEffect(() => {
@@ -532,6 +555,7 @@ export function Layout() {
const showArchiveBadge = id === 'archives' && pendingUploadsCount > 0;
const badgeCount = showQueueBadge ? pendingQueueCount : showArchiveBadge ? pendingUploadsCount : 0;
const showBadge = showQueueBadge || showArchiveBadge;
const showClearPlateDot = id === 'printers' && needsClearPlate;
return (
<li
@@ -566,6 +590,9 @@ export function Layout() {
)}
<div className="relative">
<Icon className="w-5 h-5 flex-shrink-0" />
{showClearPlateDot && (
<span className="absolute -top-0.5 -right-0.5 w-2.5 h-2.5 bg-yellow-500 rounded-full border-2 border-bambu-dark-secondary" />
)}
{showBadge && (
<span className={`absolute -top-1.5 -right-1.5 min-w-[18px] h-[18px] px-1 flex items-center justify-center text-[10px] font-bold rounded-full ${
showArchiveBadge ? 'bg-blue-500 text-white' : 'bg-yellow-500 text-black'