import { useState } from "preact/hooks"; import { useT } from "@shared/i18n/context"; import { useTestConnection } from "@shared/hooks/use-test-connection"; import type { DiagnosticCheck, DiagnosticStatus } from "@shared/types"; const STATUS_COLORS: Record = { pass: "text-green-600 dark:text-green-400", fail: "text-red-500 dark:text-red-400", skip: "text-slate-400 dark:text-text-dim", }; const STATUS_BG: Record = { pass: "bg-green-50 dark:bg-green-900/20 border-green-200 dark:border-green-800", fail: "bg-red-50 dark:bg-red-900/20 border-red-200 dark:border-red-800", skip: "bg-slate-50 dark:bg-[#161b22] border-slate-200 dark:border-border-dark", }; const CHECK_NAME_KEYS: Record = { server: "checkServer", accounts: "checkAccounts", transport: "checkTransport", upstream: "checkUpstream", }; const STATUS_KEYS: Record = { pass: "statusPass", fail: "statusFail", skip: "statusSkip", }; function StatusIcon({ status }: { status: DiagnosticStatus }) { if (status === "pass") { return ( ); } if (status === "fail") { return ( ); } return ( ); } function CheckRow({ check }: { check: DiagnosticCheck }) { const t = useT(); const nameKey = CHECK_NAME_KEYS[check.name] ?? check.name; const statusKey = STATUS_KEYS[check.status]; return (
{t(nameKey as Parameters[0])} {t(statusKey as Parameters[0])} {check.latencyMs > 0 && ( {check.latencyMs}ms )}
{check.detail && (

{check.detail}

)} {check.error && (

{check.error}

)}
); } export function TestConnection() { const t = useT(); const { testing, result, error, runTest } = useTestConnection(); const [collapsed, setCollapsed] = useState(true); return (
{/* Header */} {/* Content */} {!collapsed && (
{/* Run test button */} {/* Error */} {error && (

{error}

)} {/* Results */} {result && (
{result.checks.map((check) => ( ))}
)}
)}
); }