Keep showing steps

This commit is contained in:
Desktop
2025-11-11 00:02:49 +05:00
parent 727c999413
commit 51f8e07634

View File

@@ -150,14 +150,78 @@ export default function ProgressModal({
stepLogs = [], stepLogs = [],
}: ProgressModalProps) { }: ProgressModalProps) {
const hasAutoClosedRef = useRef(false); const hasAutoClosedRef = useRef(false);
// Track which steps are visually completed (with delay)
const [visuallyCompletedSteps, setVisuallyCompletedSteps] = React.useState<Set<string>>(new Set());
const stepCompletionTimersRef = useRef<Map<string, NodeJS.Timeout>>(new Map());
// Auto-close on completion after 3 seconds // Get steps for this function
const steps = getStepsForFunction(functionId, title);
const currentPhase = getCurrentPhase(stepLogs, percentage);
// Track step completions with 2-second delay between each step
useEffect(() => {
if (!isOpen) {
// Reset when modal closes
setVisuallyCompletedSteps(new Set());
stepCompletionTimersRef.current.forEach(timer => clearTimeout(timer));
stepCompletionTimersRef.current.clear();
return;
}
const phaseOrder = ['INIT', 'PREP', 'AI_CALL', 'PARSE', 'SAVE', 'DONE'];
// Check each step in order
steps.forEach((step, index) => {
const stepPhase = step.phase;
const stepIndex = phaseOrder.indexOf(stepPhase);
const currentIndex = phaseOrder.indexOf(currentPhase);
// Check if step should be completed (we've moved past it or have log entry)
const shouldBeCompleted = currentIndex > stepIndex ||
stepLogs.some(log => log.stepName === stepPhase && log.status === 'success');
// If step should be completed but isn't visually completed yet
if (shouldBeCompleted && !visuallyCompletedSteps.has(stepPhase)) {
// Check if previous step is visually completed (or if this is the first step)
const previousStep = index > 0 ? steps[index - 1] : null;
const previousStepCompleted = !previousStep || visuallyCompletedSteps.has(previousStep.phase);
// Only schedule if previous step is completed (or this is first step)
if (previousStepCompleted) {
// Clear any existing timer for this step
const existingTimer = stepCompletionTimersRef.current.get(stepPhase);
if (existingTimer) {
clearTimeout(existingTimer);
}
// Calculate delay: 2 seconds after previous step visually completed (or 0 for first step)
const delay = previousStep ? 2000 : 0;
// Schedule completion
const timer = setTimeout(() => {
setVisuallyCompletedSteps(prev => new Set([...prev, stepPhase]));
stepCompletionTimersRef.current.delete(stepPhase);
}, delay);
stepCompletionTimersRef.current.set(stepPhase, timer);
}
}
});
// Cleanup on unmount
return () => {
stepCompletionTimersRef.current.forEach(timer => clearTimeout(timer));
stepCompletionTimersRef.current.clear();
};
}, [isOpen, currentPhase, stepLogs, steps, visuallyCompletedSteps]);
// Auto-close on completion after 5 seconds (increased to allow all steps to show)
useEffect(() => { useEffect(() => {
if (status === 'completed' && onClose && !hasAutoClosedRef.current) { if (status === 'completed' && onClose && !hasAutoClosedRef.current) {
hasAutoClosedRef.current = true; hasAutoClosedRef.current = true;
const timer = setTimeout(() => { const timer = setTimeout(() => {
onClose(); onClose();
}, 3000); }, 5000);
return () => clearTimeout(timer); return () => clearTimeout(timer);
} }
if (status !== 'completed') { if (status !== 'completed') {
@@ -165,14 +229,11 @@ export default function ProgressModal({
} }
}, [status, onClose]); }, [status, onClose]);
// Get steps for this function // Build checklist items with visual completion state
const steps = getStepsForFunction(functionId, title);
const currentPhase = getCurrentPhase(stepLogs, percentage);
// Build checklist items
const checklistItems = steps.map((step) => { const checklistItems = steps.map((step) => {
const completed = isStepCompleted(step.phase, currentPhase, stepLogs); const actuallyCompleted = isStepCompleted(step.phase, currentPhase, stepLogs);
const inProgress = isStepInProgress(step.phase, currentPhase); const visuallyCompleted = visuallyCompletedSteps.has(step.phase);
const inProgress = isStepInProgress(step.phase, currentPhase) && !visuallyCompleted;
// Get user-friendly message from step logs if available // Get user-friendly message from step logs if available
const stepLog = stepLogs.find(log => log.stepName === step.phase); const stepLog = stepLogs.find(log => log.stepName === step.phase);
@@ -181,7 +242,7 @@ export default function ProgressModal({
return { return {
label: stepMessage, label: stepMessage,
phase: step.phase, phase: step.phase,
completed, completed: visuallyCompleted, // Use visual completion state
inProgress, inProgress,
}; };
}); });
@@ -200,12 +261,15 @@ export default function ProgressModal({
<div className="p-6 min-h-[200px]"> <div className="p-6 min-h-[200px]">
{/* Header */} {/* Header */}
<div className="flex items-start gap-4 mb-6"> <div className="flex items-start gap-4 mb-6">
{!showSuccess && (
<div className="flex-shrink-0 mt-1"> <div className="flex-shrink-0 mt-1">
{status === 'error' ? ( {status === 'error' ? (
<svg className="w-6 h-6 text-error-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg className="w-6 h-6 text-error-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg> </svg>
) : showSuccess ? (
<svg className="w-6 h-6 text-success-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
</svg>
) : ( ) : (
<svg className="w-6 h-6 text-brand-500 animate-spin" fill="none" viewBox="0 0 24 24"> <svg className="w-6 h-6 text-brand-500 animate-spin" fill="none" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" /> <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
@@ -213,7 +277,6 @@ export default function ProgressModal({
</svg> </svg>
)} )}
</div> </div>
)}
<div className="flex-1"> <div className="flex-1">
<h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-1"> <h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-1">
{title} {title}
@@ -238,8 +301,7 @@ export default function ProgressModal({
</div> </div>
)} )}
{/* Checklist-style Progress Steps */} {/* Checklist-style Progress Steps - Always visible */}
{!showSuccess && (
<div className="mb-6 space-y-3"> <div className="mb-6 space-y-3">
{checklistItems.map((item, index) => ( {checklistItems.map((item, index) => (
<div <div
@@ -283,7 +345,6 @@ export default function ProgressModal({
</div> </div>
))} ))}
</div> </div>
)}
{/* Footer */} {/* Footer */}
<div className="flex justify-end gap-3"> <div className="flex justify-end gap-3">