mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-07 23:01:06 +02:00
Follow-up to 0f203ce: force color match now picks the right AMS slot, not
just the right printer. The slot mapper cleared tray_info_idx when applying
an override, so on a printer holding two same-colour PLA spools of different
variants (Basic GFA00 / Matte GFA01 / Silk GFA06) it could map to the wrong
one. It now keeps the variant for force_color_match overrides (both the 3MF
and no-3MF fallback paths) so the matcher pins the matching tray, and falls
back to type+colour when that variant isn't loaded. A manual filament swap
(a preference override) still clears the idx so it matches the swapped-in
spool rather than the old one.
The printer-card queue-compatibility hint applies the same variant rule.
76 lines
3.4 KiB
TypeScript
76 lines
3.4 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
|
|
loadedVariants?: Set<string>; // "TYPE:rrggbb:idx" triples for PLA sub-variant matching (#2650)
|
|
variant?: 'card' | 'panelExtension';
|
|
}
|
|
|
|
export function PrinterQueueWidget({ printerId, printerModel, loadedFilamentTypes, loadedFilaments, loadedVariants, variant = 'card' }: 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, loadedVariants) : 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.
|
|
const linkClassName = variant === 'panelExtension'
|
|
? 'block mt-2 border-t border-bambu-dark-tertiary pt-2 pl-1 hover:opacity-90 transition-opacity'
|
|
: 'block mb-3 p-3 bg-bambu-dark rounded-lg hover:bg-bambu-dark-tertiary transition-colors';
|
|
|
|
return (
|
|
<Link
|
|
to="/queue"
|
|
className={linkClassName}
|
|
>
|
|
<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-600 dark: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-100 dark:bg-yellow-400/20 text-yellow-700 dark:text-yellow-400 rounded">
|
|
+{totalPending - 1}
|
|
</span>
|
|
)}
|
|
<ChevronRight className="w-4 h-4 text-bambu-gray" />
|
|
</div>
|
|
</div>
|
|
</Link>
|
|
);
|
|
}
|