import { useRef } from "react"; import { Button } from "~/components/ui/button"; import { Card } from "~/components/ui/card"; import { useFocusTrap } from "~/hooks/useFocusTrap"; interface ConnectionOverlayProps { isConnected: boolean; isReconnecting: boolean; connectionError: string | null; isSyncing: boolean; } export function ConnectionOverlay({ isConnected, isReconnecting, connectionError, isSyncing, }: ConnectionOverlayProps) { const isVisible = !isConnected || isSyncing; const dialogRef = useRef(null); const titleId = "connection-overlay-title"; useFocusTrap(dialogRef, isVisible); if (!isVisible) return null; const statusMessage = connectionError ? connectionError : isSyncing ? "Reconnected. Syncing the latest draft state..." : isReconnecting ? "Lost connection to the draft server. Attempting to reconnect..." : "Please wait while we connect you to the live draft room."; return (
{/* sr-only live region so status changes are announced without relying on aria-label on the dots */} {statusMessage} {/* tabIndex allows the card to receive focus when there are no interactive children (spinner state) */}
{/* Spinner or Error Icon */} {connectionError ? (
) : (