import React from 'react'
import { api } from '../lib/api'
import { useQuery } from '@tanstack/react-query'
export const FlareSolverrStatus: React.FC = () => {
const { data, isLoading, error, refetch } = useQuery({
queryKey: ['flaresolverr-health'],
queryFn: () => api.getFlareSolverrHealth(),
refetchInterval: 30000, // Check every 30 seconds
retry: 1
})
const getStatusColor = (status?: string) => {
switch (status) {
case 'healthy':
return 'bg-green-500'
case 'unhealthy':
return 'bg-yellow-500'
case 'offline':
case 'timeout':
case 'error':
return 'bg-red-500'
default:
return 'bg-gray-500'
}
}
const getStatusText = (status?: string) => {
switch (status) {
case 'healthy':
return 'Healthy'
case 'unhealthy':
return 'Unhealthy'
case 'offline':
return 'Offline'
case 'timeout':
return 'Timeout'
case 'error':
return 'Error'
default:
return 'Unknown'
}
}
const getStatusIcon = (status?: string) => {
switch (status) {
case 'healthy':
return (
)
case 'unhealthy':
return (
)
default:
return (
)
}
}
if (isLoading) {
return (
)
}
if (error) {
return (
Failed to check FlareSolverr
)
}
return (
{/* Status Indicator */}
{/* Status Badge */}
{getStatusIcon(data?.status)}
{getStatusText(data?.status)}
{/* Response Time (if healthy) */}
{data?.status === 'healthy' && data.response_time_ms && (
{data.response_time_ms}ms
)}
{/* Sessions Count (if healthy) */}
{data?.status === 'healthy' && data.sessions && (
{data.sessions.length} session{data.sessions.length !== 1 ? 's' : ''}
)}
{/* Error Message (if not healthy) */}
{data?.status !== 'healthy' && data?.error && (
{data.error}
)}
{/* Manual Refresh Button */}
)
}
// Compact version for sidebar or small spaces
export const FlareSolverrStatusCompact: React.FC = () => {
const { data, isLoading } = useQuery({
queryKey: ['flaresolverr-health'],
queryFn: () => api.getFlareSolverrHealth(),
refetchInterval: 30000,
retry: 1
})
const getStatusColor = (status?: string) => {
switch (status) {
case 'healthy':
return 'bg-green-500'
case 'unhealthy':
return 'bg-yellow-500'
case 'offline':
case 'timeout':
case 'error':
return 'bg-red-500'
default:
return 'bg-gray-500'
}
}
if (isLoading) {
return
}
return (
)
}