import { useState, useEffect, useRef } from 'react'; import { useNavigate, useLocation } from 'react-router'; import { motion } from 'motion/react'; import { Check, AlertCircle } from 'lucide-react'; import { generateMarketingReport } from '../lib/supabase'; const steps = [ { label: 'Scanning website...', key: 'scrape' }, { label: 'Analyzing social media presence...', key: 'social' }, { label: 'Researching competitors & keywords...', key: 'analyze' }, { label: 'Generating AI marketing report...', key: 'generate' }, { label: 'Finalizing report...', key: 'finalize' }, ]; export default function AnalysisLoadingPage() { const [currentStep, setCurrentStep] = useState(0); const [error, setError] = useState(null); const navigate = useNavigate(); const location = useLocation(); const url = (location.state as { url?: string })?.url; const hasStarted = useRef(false); useEffect(() => { if (hasStarted.current) return; hasStarted.current = true; if (!url) { navigate('/', { replace: true }); return; } const runAnalysis = async () => { try { // Step 1: Scraping setCurrentStep(1); // Simulate step progression while waiting for API const stepTimer = setInterval(() => { setCurrentStep((prev) => (prev < steps.length - 1 ? prev + 1 : prev)); }, 5000); const result = await generateMarketingReport(url); clearInterval(stepTimer); setCurrentStep(steps.length); if (result.success && result.report) { const reportPath = result.reportId ? `/report/${result.reportId}` : '/report/live'; // Brief delay to show completion setTimeout(() => { navigate(reportPath, { replace: true, state: { report: result.report, metadata: result.metadata, reportId: result.reportId, }, }); }, 800); } else { throw new Error(result.error || 'Report generation failed'); } } catch (err) { setError(err instanceof Error ? err.message : 'An error occurred'); } }; runAnalysis(); }, [url, navigate]); return (
INFINITH {url && ( {url} )} {error ? (

{error}

) : ( <>
{steps.map((step, index) => { const isCompleted = currentStep > index; const isActive = currentStep === index + 1 && currentStep <= steps.length; return (
{isCompleted ? ( ) : isActive ? (
) : (
)}
{step.label} ); })}

AI가 마케팅 데이터를 분석하고 있습니다. 약 20~30초 소요됩니다.

)}
); }