mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-18 03:54:17 +02:00
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:
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user