Spaces:
Sleeping
Sleeping
Elvis Claude Opus 4.5 commited on
Commit Β·
aa69780
1
Parent(s): f0b0450
Fix loading animation loop and add progress bar
Browse files- Steps no longer loop back to beginning (was causing "stuck" appearance)
- Added visual progress bar with percentage
- Last step shows "Finishing up..." when waiting for API
- Spinner on active step instead of pulsing dot
π€ Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
123456789101112131415161718192021222324255 unmodified lines3132333435363738393 unmodified lines434445464748495051525354555657585960616263646566676869707172737475import { useState, useEffect } from 'react'const analysisSteps = [{ text: 'Analyzing depth of field...', icon: 'π' },{ text: 'Detecting light sources...', icon: 'π‘' },{ text: 'Extracting color palette...', icon: 'π¨' },{ text: 'Estimating focal length...', icon: 'π·' },{ text: 'Mapping shadows...', icon: 'π' },{ text: 'Generating recommendations...', icon: 'β¨' },]function LoadingAnalysis({ imagePreview }) {const [currentStep, setCurrentStep] = useState(0)useEffect(() => {const interval = setInterval(() => {setCurrentStep((prev) => (prev + 1) % analysisSteps.length)}, 1500)return () => clearInterval(interval)}, [])return (<div className="max-w-4xl mx-auto"><div className="grid md:grid-cols-2 gap-8 items-center">5 unmodified lines/><div className="absolute inset-0 bg-gradient-to-t from-slate-900/80 to-transparent rounded-xl" /><div className="absolute bottom-4 left-4 right-4"><div className="flex items-center gap-3 text-white"><div className="animate-spin w-5 h-5 border-2 border-white border-t-transparent rounded-full" /><span className="text-sm font-medium">Processing image...</span></div></div></div>3 unmodified linesAnalyzing Your Shot</h3>{analysisSteps.map((step, index) => (<divkey={index}className={`flex items-center gap-3 p-3 rounded-lg transition-all ${index === currentStep? 'bg-amber-500/20 border border-amber-500/50': index < currentStep? 'bg-slate-800/50 opacity-50': 'bg-slate-800/30 opacity-30'}`}><span className="text-xl">{step.icon}</span><span className={`text-sm ${index === currentStep ? 'text-white' : 'text-slate-400'}`}>{step.text}</span>{index === currentStep && (<div className="ml-auto"><div className="animate-pulse w-2 h-2 bg-amber-500 rounded-full" /></div>)}{index < currentStep && (<svg className="ml-auto w-5 h-5 text-green-500" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" /></svg>)}</div>))}</div></div></div>1234567891011121314151617181920212223242526272829303132333435363738394041424344455 unmodified lines51525354555657585960616263646566673 unmodified lines7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110import { useState, useEffect } from 'react'const analysisSteps = [{ text: 'Reading image metadata...', icon: 'π·' },{ text: 'Analyzing depth of field...', icon: 'π' },{ text: 'Detecting light sources...', icon: 'π‘' },{ text: 'Extracting color palette...', icon: 'π¨' },{ text: 'Analyzing tone curve...', icon: 'π' },{ text: 'Generating recommendations...', icon: 'β¨' },]function LoadingAnalysis({ imagePreview }) {const [currentStep, setCurrentStep] = useState(0)const [elapsedTime, setElapsedTime] = useState(0)useEffect(() => {// Progress through steps without loopingconst stepInterval = setInterval(() => {setCurrentStep((prev) => {// Stop at the last step instead of loopingif (prev >= analysisSteps.length - 1) {return prev}return prev + 1})}, 800)// Track elapsed time for the progress barconst timeInterval = setInterval(() => {setElapsedTime((prev) => prev + 100)}, 100)return () => {clearInterval(stepInterval)clearInterval(timeInterval)}}, [])// Estimate progress (assume ~5 seconds typical analysis time)const estimatedDuration = 5000const progress = Math.min((elapsedTime / estimatedDuration) * 100, 95)return (<div className="max-w-4xl mx-auto"><div className="grid md:grid-cols-2 gap-8 items-center">5 unmodified lines/><div className="absolute inset-0 bg-gradient-to-t from-slate-900/80 to-transparent rounded-xl" /><div className="absolute bottom-4 left-4 right-4"><div className="flex items-center gap-3 text-white mb-2"><div className="animate-spin w-5 h-5 border-2 border-white border-t-transparent rounded-full" /><span className="text-sm font-medium">Processing image...</span><span className="ml-auto text-xs text-slate-300">{Math.round(progress)}%</span></div>{/* Progress bar */}<div className="h-1 bg-slate-700 rounded-full overflow-hidden"><divclassName="h-full bg-gradient-to-r from-amber-500 to-orange-500 transition-all duration-300 ease-out"style={{ width: `${progress}%` }}/></div></div></div>3 unmodified linesAnalyzing Your Shot</h3>{analysisSteps.map((step, index) => {const isActive = index === currentStepconst isComplete = index < currentStepconst isLast = index === analysisSteps.length - 1const isWaiting = isActive && isLast && progress > 80return (<divkey={index}className={`flex items-center gap-3 p-3 rounded-lg transition-all ${isActive? 'bg-amber-500/20 border border-amber-500/50': isComplete? 'bg-slate-800/50': 'bg-slate-800/30 opacity-30'}`}><span className="text-xl">{step.icon}</span><span className={`text-sm ${isActive ? 'text-white' : isComplete ? 'text-slate-300' : 'text-slate-400'}`}>{isWaiting ? 'Finishing up...' : step.text}</span>{isActive && (<div className="ml-auto"><div className="animate-spin w-4 h-4 border-2 border-amber-500 border-t-transparent rounded-full" /></div>)}{isComplete && (<svg className="ml-auto w-5 h-5 text-green-500" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" /></svg>)}</div>)})}</div></div></div>
frontend/src/components/LoadingAnalysis.jsx+69-34