import { useQuery } from '@tanstack/react-query'; import { Clock, Calendar, ChevronRight } from 'lucide-react'; import { Link } from 'react-router-dom'; import { api } from '../api/client'; interface PrinterQueueWidgetProps { printerId: number; } function formatRelativeTime(dateString: string | null): string { if (!dateString) return 'ASAP'; const date = new Date(dateString); const now = new Date(); const diff = date.getTime() - now.getTime(); if (diff < 0) return 'Now'; if (diff < 60000) return 'In <1 min'; if (diff < 3600000) return `In ${Math.round(diff / 60000)} min`; if (diff < 86400000) return `In ${Math.round(diff / 3600000)}h`; return date.toLocaleDateString(); } export function PrinterQueueWidget({ printerId }: PrinterQueueWidgetProps) { const { data: queue } = useQuery({ queryKey: ['queue', printerId, 'pending'], queryFn: () => api.getQueue(printerId, 'pending'), refetchInterval: 30000, }); const nextItem = queue?.[0]; const totalPending = queue?.length || 0; if (totalPending === 0) { return null; } return (

Next in queue

{nextItem?.archive_name || `Archive #${nextItem?.archive_id}`}

{formatRelativeTime(nextItem?.scheduled_time || null)} {totalPending > 1 && ( +{totalPending - 1} )}
); }