mirror of
https://github.com/block/buzz.git
synced 2026-11-13 04:41:12 +00:00
Signed-off-by: Will Pfleger <pfleger.will@gmail.com> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
110 lines
3.0 KiB
TypeScript
110 lines
3.0 KiB
TypeScript
import { Check, CloudOff } from "lucide-react";
|
|
|
|
import {
|
|
SidebarCompactActionCard,
|
|
type SidebarActionCardSurface,
|
|
} from "@/shared/ui/sidebar-action-card";
|
|
import { Spinner } from "@/shared/ui/spinner";
|
|
|
|
type SidebarRelayConnectionCardProps = {
|
|
isActionDisabled?: boolean;
|
|
actionTestId?: string;
|
|
className?: string;
|
|
isConnected?: boolean;
|
|
isReconnectPending: boolean;
|
|
isWaitingOnReconnectHook?: boolean;
|
|
onDismiss?: () => void;
|
|
onReconnect: () => void;
|
|
surface?: SidebarActionCardSurface;
|
|
testId?: string;
|
|
};
|
|
|
|
export function SidebarRelayConnectionCard({
|
|
actionTestId,
|
|
className,
|
|
isActionDisabled = false,
|
|
isConnected = false,
|
|
isReconnectPending,
|
|
isWaitingOnReconnectHook = false,
|
|
onDismiss,
|
|
onReconnect,
|
|
surface,
|
|
}: SidebarRelayConnectionCardProps) {
|
|
return (
|
|
<SidebarRelayConnectionCompactCard
|
|
actionTestId={actionTestId ?? "sidebar-reconnect"}
|
|
className={className}
|
|
isActionDisabled={isActionDisabled}
|
|
isConnected={isConnected}
|
|
isReconnectPending={isReconnectPending}
|
|
isWaitingOnReconnectHook={isWaitingOnReconnectHook}
|
|
onDismiss={onDismiss}
|
|
onReconnect={onReconnect}
|
|
surface={surface}
|
|
testId="sidebar-relay-unreachable"
|
|
/>
|
|
);
|
|
}
|
|
|
|
export function SidebarRelayConnectionCompactCard({
|
|
actionTestId,
|
|
className,
|
|
isActionDisabled = false,
|
|
isConnected = false,
|
|
isReconnectPending,
|
|
isWaitingOnReconnectHook = false,
|
|
onDismiss,
|
|
onReconnect,
|
|
surface,
|
|
testId = "sidebar-relay-unreachable-compact",
|
|
}: SidebarRelayConnectionCardProps) {
|
|
const reconnectTitle = isWaitingOnReconnectHook
|
|
? "Waiting to reconnect"
|
|
: "Connecting";
|
|
const reconnectDescription = isWaitingOnReconnectHook
|
|
? "Complete any prompts opened by the reconnect helper to continue."
|
|
: "Reconnecting";
|
|
|
|
return (
|
|
<SidebarCompactActionCard
|
|
actionAriaLabel={isConnected ? "Connected" : "Connect to relay"}
|
|
actionDisabled={isActionDisabled || isReconnectPending || isConnected}
|
|
actionTestId={actionTestId}
|
|
description={
|
|
isConnected
|
|
? undefined
|
|
: isReconnectPending
|
|
? reconnectDescription
|
|
: "Click to connect"
|
|
}
|
|
dismissLabel="Dismiss relay notification"
|
|
iconKey={
|
|
isConnected ? "connected" : isReconnectPending ? "pending" : "idle"
|
|
}
|
|
icon={
|
|
isConnected ? (
|
|
<Check aria-hidden="true" className="h-5 w-5" />
|
|
) : isReconnectPending ? (
|
|
<Spinner aria-hidden="true" className="h-5 w-5 border-2" />
|
|
) : (
|
|
<CloudOff aria-hidden="true" className="h-5 w-5" />
|
|
)
|
|
}
|
|
className={className}
|
|
onAction={onReconnect}
|
|
onDismiss={onDismiss}
|
|
role={isConnected ? "status" : "alert"}
|
|
surface={surface}
|
|
testId={testId}
|
|
title={
|
|
isConnected
|
|
? "Connected"
|
|
: isReconnectPending
|
|
? reconnectTitle
|
|
: "Can't reach the relay"
|
|
}
|
|
tone={isConnected ? "success" : "neutral"}
|
|
/>
|
|
);
|
|
}
|