feat: real API integration + YouTube Data API v3 + progressive loading

- Replace mock useReport() with real Supabase API data pipeline
- Add transformReport.ts to map API responses to MarketingReport type
- Add useEnrichment() hook for background channel data enrichment
- Replace Apify YouTube scraper with YouTube Data API v3
- Add mergeEnrichment() for progressive data loading
- Add EmptyState component for graceful empty data handling
- Add socialHandles to generate-report metadata
- Graceful empty data in ClinicSnapshot, YouTube, Instagram, Facebook
- Add Supabase Edge Functions and DB migrations
- Add developer handoff documentation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Haewon KamandClaude Opus 4.6 committed 2026-04-02 10:57:14 +09:00
1 parent c6e18b6a67
commit 60cd055042
30 files changed
+2905 -142

No files matched your search

+131 -84
View File
@@ -1,52 +1,82 @@
import { useState, useEffect } from 'react';
import { useState, useEffect, useRef } from 'react';
import { useNavigate, useLocation } from 'react-router';
import { motion } from 'motion/react';
import { Check } from 'lucide-react';
import { Check, AlertCircle } from 'lucide-react';
import { generateMarketingReport } from '../lib/supabase';
const steps = [
'Scanning website...',
'Capturing channel screenshots...',
'Analyzing social media presence...',
'Evaluating brand consistency...',
'Generating intelligence report...',
{ 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<string | null>(null);
const navigate = useNavigate();
const location = useLocation();
const url = (location.state as { url?: string })?.url;
const hasStarted = useRef(false);
useEffect(() => {
const timers: ReturnType<typeof setTimeout>[] = [];
if (hasStarted.current) return;
hasStarted.current = true;
steps.forEach((_, index) => {
timers.push(
setTimeout(() => {
setCurrentStep(index + 1);
}, (index + 1) * 1250)
);
});
if (!url) {
navigate('/', { replace: true });
return;
}
timers.push(
setTimeout(() => {
navigate('/report/view-clinic', { replace: true });
}, 5500)
);
const runAnalysis = async () => {
try {
// Step 1: Scraping
setCurrentStep(1);
return () => timers.forEach(clearTimeout);
}, [navigate]);
// 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 (
<div className="relative min-h-screen bg-primary-900 flex flex-col items-center justify-center px-6 overflow-hidden">
{/* Radial gradient overlay */}
<div className="absolute inset-0 bg-[radial-gradient(ellipse_at_center,_rgba(79,29,161,0.25)_0%,_transparent_70%)]" />
{/* Purple glow blob */}
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[500px] h-[500px] bg-purple-600/20 rounded-full blur-[120px] pointer-events-none" />
<div className="relative z-10 flex flex-col items-center w-full max-w-lg">
{/* INFINITH logo text */}
<motion.h1
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
@@ -56,7 +86,6 @@ export default function AnalysisLoadingPage() {
INFINITH
</motion.h1>
{/* Entered URL */}
{url && (
<motion.p
initial={{ opacity: 0, y: 20 }}
@@ -68,64 +97,82 @@ export default function AnalysisLoadingPage() {
</motion.p>
)}
{/* Analysis steps */}
<div className="w-full space-y-5 mb-14">
{steps.map((step, index) => {
const isCompleted = currentStep > index;
const isActive = currentStep === index;
return (
<motion.div
key={step}
initial={{ opacity: 0, x: -20 }}
animate={{ opacity: isActive || isCompleted ? 1 : 0.3, x: 0 }}
transition={{ duration: 0.4, delay: index * 0.15 }}
className="flex items-center gap-4"
>
{/* Status icon */}
<div className="w-7 h-7 flex-shrink-0 flex items-center justify-center">
{isCompleted ? (
<motion.div
initial={{ scale: 0 }}
animate={{ scale: 1 }}
transition={{ type: 'spring', stiffness: 300, damping: 20 }}
className="w-7 h-7 rounded-full bg-gradient-to-r from-[#4F1DA1] to-[#6C5CE7] flex items-center justify-center"
>
<Check className="w-4 h-4 text-white" strokeWidth={3} />
</motion.div>
) : isActive ? (
<div className="w-7 h-7 rounded-full border-2 border-purple-400 border-t-transparent animate-spin" />
) : (
<div className="w-7 h-7 rounded-full border-2 border-white/10" />
)}
</div>
{/* Step text */}
<span
className={`text-base font-sans transition-colors duration-300 ${
isCompleted
? 'text-white'
: isActive
? 'text-purple-200'
: 'text-white/30'
}`}
>
{step}
</span>
</motion.div>
);
})}
</div>
{/* Progress bar */}
<div className="w-full h-2 bg-white/10 rounded-full overflow-hidden">
{error ? (
<motion.div
initial={{ width: '0%' }}
animate={{ width: '100%' }}
transition={{ duration: 5, ease: 'linear' }}
className="h-full bg-gradient-to-r from-[#4F1DA1] to-[#6C5CE7] rounded-full"
/>
</div>
initial={{ opacity: 0, scale: 0.95 }}
animate={{ opacity: 1, scale: 1 }}
className="w-full p-6 rounded-2xl bg-red-500/10 border border-red-500/20 text-center"
>
<AlertCircle className="w-10 h-10 text-red-400 mx-auto mb-3" />
<p className="text-red-300 text-sm mb-4">{error}</p>
<button
onClick={() => navigate('/', { replace: true })}
className="px-6 py-2 text-sm font-medium text-white bg-white/10 rounded-lg hover:bg-white/20 transition-colors"
>
Try Again
</button>
</motion.div>
) : (
<>
<div className="w-full space-y-5 mb-14">
{steps.map((step, index) => {
const isCompleted = currentStep > index;
const isActive = currentStep === index + 1 && currentStep <= steps.length;
return (
<motion.div
key={step.key}
initial={{ opacity: 0, x: -20 }}
animate={{ opacity: isActive || isCompleted ? 1 : 0.3, x: 0 }}
transition={{ duration: 0.4, delay: index * 0.15 }}
className="flex items-center gap-4"
>
<div className="w-7 h-7 flex-shrink-0 flex items-center justify-center">
{isCompleted ? (
<motion.div
initial={{ scale: 0 }}
animate={{ scale: 1 }}
transition={{ type: 'spring', stiffness: 300, damping: 20 }}
className="w-7 h-7 rounded-full bg-gradient-to-r from-[#4F1DA1] to-[#6C5CE7] flex items-center justify-center"
>
<Check className="w-4 h-4 text-white" strokeWidth={3} />
</motion.div>
) : isActive ? (
<div className="w-7 h-7 rounded-full border-2 border-purple-400 border-t-transparent animate-spin" />
) : (
<div className="w-7 h-7 rounded-full border-2 border-white/10" />
)}
</div>
<span
className={`text-base font-sans transition-colors duration-300 ${
isCompleted
? 'text-white'
: isActive
? 'text-purple-200'
: 'text-white/30'
}`}
>
{step.label}
</span>
</motion.div>
);
})}
</div>
<div className="w-full h-2 bg-white/10 rounded-full overflow-hidden">
<motion.div
initial={{ width: '0%' }}
animate={{ width: `${(currentStep / steps.length) * 100}%` }}
transition={{ duration: 0.8, ease: 'easeInOut' }}
className="h-full bg-gradient-to-r from-[#4F1DA1] to-[#6C5CE7] rounded-full"
/>
</div>
<p className="text-white/40 text-xs mt-4">
AI가 마케팅 데이터를 분석하고 있습니다. 약 20~30초 소요됩니다.
</p>
</>
)}
</div>
</div>
);