import { useEffect, useState } from 'react'; import { Link, useNavigate } from 'react-router-dom'; import PageMeta from '../../components/common/PageMeta'; import ComponentCard from '../../components/common/ComponentCard'; import EnhancedMetricCard from '../../components/dashboard/EnhancedMetricCard'; import PageHeader from '../../components/common/PageHeader'; import { FileTextIcon, ArrowRightIcon, PlugInIcon, ArrowUpIcon } from '../../icons'; import { fetchContent } from '../../services/api'; import { useSiteStore } from '../../store/siteStore'; import { useSectorStore } from '../../store/sectorStore'; interface LinkerStats { totalLinked: number; totalLinks: number; averageLinksPerContent: number; contentWithLinks: number; contentWithoutLinks: number; } export default function LinkerDashboard() { const navigate = useNavigate(); const { activeSite } = useSiteStore(); const { activeSector } = useSectorStore(); const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { fetchDashboardData(); }, [activeSite, activeSector]); const fetchDashboardData = async () => { try { setLoading(true); // Fetch content to calculate stats const contentRes = await fetchContent({ page_size: 1000, sector_id: activeSector?.id, }); const content = contentRes.results || []; // Calculate stats const contentWithLinks = content.filter(c => c.internal_links && c.internal_links.length > 0); const totalLinks = content.reduce((sum, c) => sum + (c.internal_links?.length || 0), 0); const averageLinksPerContent = contentWithLinks.length > 0 ? (totalLinks / contentWithLinks.length) : 0; setStats({ totalLinked: contentWithLinks.length, totalLinks, averageLinksPerContent: parseFloat(averageLinksPerContent.toFixed(1)), contentWithLinks: contentWithLinks.length, contentWithoutLinks: content.length - contentWithLinks.length, }); } catch (error: any) { console.error('Error loading linker stats:', error); } finally { setLoading(false); } }; return ( <>
, color: 'blue', }} /> View Content

Manage internal linking for your content

{loading ? (

Loading stats...

) : stats ? ( <> {/* Stats Cards */}
} accentColor="blue" onClick={() => navigate('/linker/content')} /> } accentColor="purple" onClick={() => navigate('/linker/content')} /> } accentColor="green" onClick={() => navigate('/linker/content')} />
{/* Quick Actions */}

Link Content

Process content for internal linking

View Content

Browse all content items

) : (

No data available

)}
); }