Update ProgressModal.tsx
This commit is contained in:
@@ -192,10 +192,15 @@ export default function ProgressModal({
|
|||||||
functionId,
|
functionId,
|
||||||
stepLogs = [],
|
stepLogs = [],
|
||||||
}: ProgressModalProps) {
|
}: ProgressModalProps) {
|
||||||
const hasAutoClosedRef = useRef(false);
|
|
||||||
// Track which steps are visually completed (with delay)
|
// Track which steps are visually completed (with delay)
|
||||||
const [visuallyCompletedSteps, setVisuallyCompletedSteps] = React.useState<Set<string>>(new Set());
|
const [visuallyCompletedSteps, setVisuallyCompletedSteps] = React.useState<Set<string>>(new Set());
|
||||||
const stepCompletionTimersRef = useRef<Map<string, NodeJS.Timeout>>(new Map());
|
const stepCompletionTimersRef = useRef<Map<string, NodeJS.Timeout>>(new Map());
|
||||||
|
const visuallyCompletedStepsRef = useRef<Set<string>>(new Set());
|
||||||
|
|
||||||
|
// Sync ref with state
|
||||||
|
useEffect(() => {
|
||||||
|
visuallyCompletedStepsRef.current = visuallyCompletedSteps;
|
||||||
|
}, [visuallyCompletedSteps]);
|
||||||
|
|
||||||
// Get steps for this function
|
// Get steps for this function
|
||||||
const steps = getStepsForFunction(functionId, title);
|
const steps = getStepsForFunction(functionId, title);
|
||||||
@@ -307,6 +312,7 @@ export default function ProgressModal({
|
|||||||
if (!isOpen) {
|
if (!isOpen) {
|
||||||
// Reset when modal closes
|
// Reset when modal closes
|
||||||
setVisuallyCompletedSteps(new Set());
|
setVisuallyCompletedSteps(new Set());
|
||||||
|
visuallyCompletedStepsRef.current = new Set();
|
||||||
stepCompletionTimersRef.current.forEach(timer => clearTimeout(timer));
|
stepCompletionTimersRef.current.forEach(timer => clearTimeout(timer));
|
||||||
stepCompletionTimersRef.current.clear();
|
stepCompletionTimersRef.current.clear();
|
||||||
return;
|
return;
|
||||||
@@ -324,27 +330,24 @@ export default function ProgressModal({
|
|||||||
const shouldBeCompleted = currentIndex > stepIndex ||
|
const shouldBeCompleted = currentIndex > stepIndex ||
|
||||||
stepLogs.some(log => log.stepName === stepPhase && log.status === 'success');
|
stepLogs.some(log => log.stepName === stepPhase && log.status === 'success');
|
||||||
|
|
||||||
// If step should be completed but isn't visually completed yet
|
// If step should be completed but isn't visually completed yet and not already scheduled
|
||||||
if (shouldBeCompleted && !visuallyCompletedSteps.has(stepPhase)) {
|
if (shouldBeCompleted && !visuallyCompletedStepsRef.current.has(stepPhase) && !stepCompletionTimersRef.current.has(stepPhase)) {
|
||||||
// Check if previous step is visually completed (or if this is the first step)
|
// Check if previous step is visually completed (or if this is the first step)
|
||||||
const previousStep = index > 0 ? steps[index - 1] : null;
|
const previousStep = index > 0 ? steps[index - 1] : null;
|
||||||
const previousStepCompleted = !previousStep || visuallyCompletedSteps.has(previousStep.phase);
|
const previousStepCompleted = !previousStep || visuallyCompletedStepsRef.current.has(previousStep.phase);
|
||||||
|
|
||||||
// Only schedule if previous step is completed (or this is first step)
|
// Only schedule if previous step is completed (or this is first step)
|
||||||
if (previousStepCompleted) {
|
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)
|
// Calculate delay: 2 seconds after previous step visually completed (or 0 for first step)
|
||||||
const delay = previousStep ? 2000 : 0;
|
const delay = previousStep ? 2000 : 0;
|
||||||
|
|
||||||
// Schedule completion
|
// Schedule completion
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
setVisuallyCompletedSteps(prev => new Set([...prev, stepPhase]));
|
setVisuallyCompletedSteps(prev => {
|
||||||
stepCompletionTimersRef.current.delete(stepPhase);
|
const newSet = new Set([...prev, stepPhase]);
|
||||||
|
stepCompletionTimersRef.current.delete(stepPhase);
|
||||||
|
return newSet;
|
||||||
|
});
|
||||||
}, delay);
|
}, delay);
|
||||||
|
|
||||||
stepCompletionTimersRef.current.set(stepPhase, timer);
|
stepCompletionTimersRef.current.set(stepPhase, timer);
|
||||||
@@ -357,7 +360,7 @@ export default function ProgressModal({
|
|||||||
stepCompletionTimersRef.current.forEach(timer => clearTimeout(timer));
|
stepCompletionTimersRef.current.forEach(timer => clearTimeout(timer));
|
||||||
stepCompletionTimersRef.current.clear();
|
stepCompletionTimersRef.current.clear();
|
||||||
};
|
};
|
||||||
}, [isOpen, currentPhase, stepLogs, steps, visuallyCompletedSteps]);
|
}, [isOpen, currentPhase, stepLogs, steps]); // Removed visuallyCompletedSteps from dependencies
|
||||||
|
|
||||||
// Don't auto-close - user must click close button
|
// Don't auto-close - user must click close button
|
||||||
|
|
||||||
@@ -370,7 +373,7 @@ export default function ProgressModal({
|
|||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
onClose={onClose || (() => {})}
|
onClose={onClose || (() => {})}
|
||||||
className="max-w-lg"
|
className="max-w-lg"
|
||||||
showCloseButton={status === 'completed' || status === 'error'}
|
showCloseButton={false}
|
||||||
>
|
>
|
||||||
<div className="p-6 min-h-[200px]">
|
<div className="p-6 min-h-[200px]">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
|
|||||||
Reference in New Issue
Block a user