mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-04 21:21:54 +02:00
In expanded view, PrinterQueueWidget rendered its own "Clear Plate & Start Next" button inside a yellow-bordered card whenever the plate-clear gate was up and an auto-dispatch item was queued. PR #939 added the card-level "Mark plate as cleared" button that already covers that state — and every other state (staged-only queue, empty queue, etc.) — so both buttons hit the same /clear-plate endpoint with identical optimistic-update semantics. Two controls, one action, visible together in one specific state. Remove the widget's button and its entire needsClearPlate render branch. The widget becomes a passive "Next in queue" preview linking to /queue; the card-level button remains the single plate-clear entry point. Also drop: - now-dead awaitingPlateClear / requirePlateClear / printerState props from PrinterQueueWidgetProps and the matching call site - orphaned queue.clearPlate / queue.plateReady translations from all eight locale files (queue.clearPlateSuccess stays — used by the card button's success toast) - PrinterQueueWidgetClearPlate.test.tsx (654 lines) — every test asserted the behaviour of the now-gone button; PrinterQueueWidget.test.tsx still covers the passive-link path Deliberately *not* changed: plate-status pill stays inside the Status box (lines 2664/2671/2736/2783 of PrintersPage.tsx). Compact-view (Size S) pill and icon-only clear button at :2664/:2671/:2673 untouched.
70 lines
3.0 KiB
TypeScript
70 lines
3.0 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { Clock, Calendar, ChevronRight } from 'lucide-react';
|
|
import { Link } from 'react-router-dom';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { api } from '../api/client';
|
|
import { formatRelativeTime } from '../utils/date';
|
|
import { filterCompatibleQueueItems } from '../utils/printer';
|
|
|
|
interface PrinterQueueWidgetProps {
|
|
printerId: number;
|
|
printerModel?: string | null;
|
|
loadedFilamentTypes?: Set<string>;
|
|
loadedFilaments?: Set<string>; // "TYPE:rrggbb" pairs for filament override color matching
|
|
}
|
|
|
|
export function PrinterQueueWidget({ printerId, printerModel, loadedFilamentTypes, loadedFilaments }: PrinterQueueWidgetProps) {
|
|
const { t } = useTranslation();
|
|
const { data: queue } = useQuery({
|
|
queryKey: ['queue', printerId, 'pending', printerModel],
|
|
queryFn: () => api.getQueue(printerId, 'pending', printerModel || undefined),
|
|
refetchInterval: 30000,
|
|
});
|
|
|
|
// Filter queue to items this printer can actually print (filament type + color check)
|
|
const compatibleQueue = queue ? filterCompatibleQueueItems(queue, loadedFilamentTypes, loadedFilaments) : undefined;
|
|
const totalPending = compatibleQueue?.length || 0;
|
|
|
|
if (totalPending === 0) {
|
|
return null;
|
|
}
|
|
|
|
const nextItem = compatibleQueue?.[0];
|
|
|
|
// Passive next-in-queue preview. Plate-clear acknowledgment is handled by the
|
|
// card-level "Mark plate as cleared" button (PrintersPage.tsx). Having a
|
|
// second button in this widget caused the two controls to overlap whenever
|
|
// the plate-clear gate was up with auto-dispatch items queued — both POSTed
|
|
// to the same /clear-plate endpoint, so the widget button was pure noise.
|
|
return (
|
|
<Link
|
|
to="/queue"
|
|
className="block mb-3 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors"
|
|
>
|
|
<div className="flex items-center justify-between gap-3">
|
|
<div className="flex items-center gap-3 min-w-0 flex-1">
|
|
<Calendar className="w-5 h-5 text-yellow-400 flex-shrink-0" />
|
|
<div className="min-w-0 flex-1">
|
|
<p className="text-xs text-bambu-gray">{t('queue.nextInQueue')}</p>
|
|
<p className="text-sm text-white truncate">
|
|
{nextItem?.archive_name || nextItem?.library_file_name || `File #${nextItem?.archive_id || nextItem?.library_file_id}`}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div className="flex items-center gap-2 flex-shrink-0">
|
|
<span className="text-xs text-bambu-gray flex items-center gap-1">
|
|
<Clock className="w-3 h-3" />
|
|
{nextItem?.scheduled_time ? formatRelativeTime(nextItem.scheduled_time, 'system', t) : t('time.waiting')}
|
|
</span>
|
|
{totalPending > 1 && (
|
|
<span className="text-xs px-1.5 py-0.5 bg-yellow-400/20 text-yellow-400 rounded">
|
|
+{totalPending - 1}
|
|
</span>
|
|
)}
|
|
<ChevronRight className="w-4 h-4 text-bambu-gray" />
|
|
</div>
|
|
</div>
|
|
</Link>
|
|
);
|
|
}
|