import { useState, useEffect } from 'react'; import { useParams, useNavigate } from 'react-router'; import PageMeta from '../../components/common/PageMeta'; import PageHeader from '../../components/common/PageHeader'; import { optimizerApi } from '../../api/optimizer.api'; import { fetchContent, Content as ContentType } from '../../services/api'; import { useToast } from '../../components/ui/toast/ToastContainer'; import { OptimizationScores } from '../../components/optimizer/OptimizationScores'; import { ArrowLeftIcon, BoltIcon } from '../../icons'; export default function AnalysisPreview() { const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const toast = useToast(); const [content, setContent] = useState(null); const [scores, setScores] = useState(null); const [loading, setLoading] = useState(true); const [analyzing, setAnalyzing] = useState(false); useEffect(() => { if (id) { loadContent(); analyzeContent(); } }, [id]); const loadContent = async () => { try { setLoading(true); // Note: fetchContent by ID would need to be implemented or use a different endpoint // For now, we'll fetch and filter const data = await fetchContent({ page_size: 1000 }); const found = data.results?.find((c: ContentType) => c.id === parseInt(id || '0')); if (found) { setContent(found); } } catch (error: any) { console.error('Error loading content:', error); toast.error(`Failed to load content: ${error.message}`); } finally { setLoading(false); } }; const analyzeContent = async () => { if (!id) return; try { setAnalyzing(true); const result = await optimizerApi.analyze(parseInt(id)); setScores(result.scores); } catch (error: any) { console.error('Error analyzing content:', error); toast.error(`Failed to analyze content: ${error.message}`); } finally { setAnalyzing(false); } }; return ( <>
, color: 'orange', }} />

Preview optimization scores without optimizing

{loading || analyzing ? (

{loading ? 'Loading content...' : 'Analyzing content...'}

) : content && scores ? (
{/* Content Info */}

{content.title || 'Untitled'}

Word Count: {content.word_count || 0} | Source: {content.source} | Status: {content.sync_status}

{/* Scores */} {/* Score Details */}

Score Details

Word Count: {scores.word_count || 0}
Has Meta Title: {scores.has_meta_title ? 'Yes' : 'No'}
Has Meta Description: {scores.has_meta_description ? 'Yes' : 'No'}
Has Primary Keyword: {scores.has_primary_keyword ? 'Yes' : 'No'}
Internal Links: {scores.internal_links_count || 0}
) : (

Content not found

)}
); }