/** * Current Processing Card Component * Shows real-time automation progress with currently processing items */ import React, { useEffect, useState } from 'react'; import { automationService, ProcessingState } from '../../services/automationService'; interface CurrentProcessingCardProps { runId: string; siteId: number; currentStage: number; onComplete?: () => void; } const CurrentProcessingCard: React.FC = ({ runId, siteId, currentStage, onComplete, }) => { const [processingState, setProcessingState] = useState(null); const [error, setError] = useState(null); useEffect(() => { let isMounted = true; const fetchState = async () => { try { const state = await automationService.getCurrentProcessing(siteId, runId); if (!isMounted) return; setProcessingState(state); setError(null); // If stage completed (all items processed), trigger refresh if (state && state.processed_items >= state.total_items && state.total_items > 0) { onComplete?.(); } } catch (err) { if (!isMounted) return; console.error('Error fetching processing state:', err); setError('Failed to load processing state'); } }; // Initial fetch fetchState(); // Poll every 3 seconds const interval = setInterval(fetchState, 3000); return () => { isMounted = false; clearInterval(interval); }; }, [siteId, runId, onComplete]); if (error) { return (

{error}

); } if (!processingState) { return null; } const percentage = processingState.percentage; return (
{/* Header */}

Automation In Progress

Stage {currentStage}: {processingState.stage_name} {processingState.stage_type}

{percentage}%
{processingState.processed_items}/{processingState.total_items} processed
{/* Progress Bar */}
{/* Currently Processing and Up Next */}
{/* Currently Processing */}

Currently Processing:

{processingState.currently_processing.length > 0 ? ( processingState.currently_processing.map((item, idx) => (
{item.title}
)) ) : (
No items currently processing
)}
{/* Up Next */}

Up Next:

{processingState.up_next.length > 0 ? ( <> {processingState.up_next.map((item, idx) => (
{item.title}
))} {processingState.remaining_count > processingState.up_next.length + processingState.currently_processing.length && (
+ {processingState.remaining_count - processingState.up_next.length - processingState.currently_processing.length} more in queue
)} ) : (
Queue empty
)}
); }; export default CurrentProcessingCard;