import { AnimatePresence, motion } from "motion/react"; import { AlertCircle } from "lucide-react"; import { SidebarRelayConnectionCard } from "@/features/sidebar/ui/SidebarRelayConnectionCard"; import type { useSidebarRelayConnectionCard } from "@/features/sidebar/ui/useSidebarRelayConnectionCard"; import { cn } from "@/shared/lib/cn"; import { useIsMobile } from "@/shared/hooks/use-mobile"; import { useRelayConnection } from "@/shared/api/useRelayConnection"; import { useSidebar } from "@/shared/ui/sidebar"; type RelayConnectionOverlayProps = { card: ReturnType; errorMessage?: string; hasWorkspaceRail?: boolean; isHuddleDrawerOpen?: boolean; }; /** * Fixed bottom-left overlay that shows the relay reconnect card when the * sidebar is collapsed. When the sidebar is open, the card lives in the * sidebar footer instead (and this overlay is hidden). Offsets itself for * the workspace rail (48px) and huddle drawer when present. * * Also surfaces non-unreachable disconnect errors (e.g. auth rejections) * when the sidebar is hidden, since those errors are only rendered inside * the sidebar content area which is off-canvas when collapsed. */ export function RelayConnectionOverlay({ card, errorMessage, hasWorkspaceRail, isHuddleDrawerOpen, }: RelayConnectionOverlayProps) { const { open: sidebarOpen, openMobile } = useSidebar(); const isMobile = useIsMobile(); const connectionState = useRelayConnection(); // Show the overlay when the sidebar surface isn't visible: // - Desktop: sidebar is collapsed (open === false) // - Mobile: the sheet is closed (openMobile === false) const isSidebarSurfaceHidden = isMobile ? !openMobile : !sidebarOpen; const shouldShowReconnectCard = card.showSidebarRelayConnectionCard && isSidebarSurfaceHidden; // Show a non-unreachable error (e.g. auth rejection) when the sidebar is // hidden and the reconnect card isn't already covering it. const hasNonUnreachableError = Boolean(errorMessage) && !card.hasRelayUnreachableError && connectionState === "disconnected"; const shouldShowErrorFallback = hasNonUnreachableError && isSidebarSurfaceHidden && !shouldShowReconnectCard; return ( {shouldShowReconnectCard ? (
) : null} {shouldShowErrorFallback ? (
) : null}
); }