'use client' import React, { useEffect, useState, useRef } from 'react'; interface ProgressBarProps { duration: number; onComplete?: () => void; } export const ProgressBar = ({ duration, onComplete }: ProgressBarProps) => { const [progress, setProgress] = useState(0); const progressInterval = useRef(null); const startTime = useRef(Date.now()); useEffect(() => { const updateProgress = () => { const currentTime = Date.now(); const elapsedTime = currentTime - startTime.current; const calculatedProgress = (elapsedTime / (duration * 1000)) * 100; if (calculatedProgress >= 95) { setProgress(95); if (progressInterval.current) { clearInterval(progressInterval.current); } onComplete?.(); return; } // Slow down progress after 90% if (calculatedProgress > 90) { const remainingProgress = Math.min(99 - progress, 0.1); setProgress(prev => prev + remainingProgress); } else { setProgress(Math.min(calculatedProgress, 90)); } }; progressInterval.current = setInterval(updateProgress, 50); return () => { if (progressInterval.current) { clearInterval(progressInterval.current); } }; }, [duration, onComplete]); return (
{/* Processing... */} {Math.round(progress)}%
); };