import { useQuery } from '@tanstack/react-query' import { Link } from 'react-router-dom' import { Activity, CheckCircle2, XCircle, AlertCircle, ArrowRight } from 'lucide-react' import { getMonitors } from '../api/uptime' import { Card, CardHeader, CardContent, Badge, Skeleton } from './ui' export default function UptimeWidget() { const { data: monitors, isLoading } = useQuery({ queryKey: ['monitors'], queryFn: getMonitors, refetchInterval: 30000, }) const upCount = monitors?.filter(m => m.status === 'up').length || 0 const downCount = monitors?.filter(m => m.status === 'down').length || 0 const totalCount = monitors?.length || 0 const allUp = totalCount > 0 && downCount === 0 const hasDown = downCount > 0 if (isLoading) { return ( {Array.from({ length: 10 }).map((_, i) => ( ))} ) } return ( Uptime Status {hasDown && ( Issues )} {totalCount === 0 ? ( No monitors configured ) : ( <> {/* Status indicator */} {allUp ? ( <> All Systems Operational > ) : hasDown ? ( <> {downCount} {downCount === 1 ? 'Site' : 'Sites'} Down > ) : ( <> Unknown Status > )} {/* Quick stats */} {upCount} up {downCount > 0 && ( {downCount} down )} {totalCount} total {/* Mini status bars */} {monitors && monitors.length > 0 && ( {monitors.slice(0, 20).map((monitor) => ( ))} {monitors.length > 20 && ( +{monitors.length - 20} )} )} > )} View detailed status ) }
No monitors configured