import { useAtomValue } from "jotai";
import { useState } from "react";
import { websocketStatusAtom, logEntriesAtom } from "./atoms";
import type { LogEntry } from "./types";
export function ReconnectingHeader() {
const status = useAtomValue(websocketStatusAtom);
if (status === "open") {
return null;
}
const message =
status === "connecting"
? "Connecting to ESAV Live..."
: "Connection lost. Attempting to reconnect...";
return (
{message}
);
}
const LogEntryItem = ({ entry }: { entry: LogEntry }) => {
const { type, timestamp, payload } = entry;
const typeStyles = {
incoming: { icon: "⬇️", color: "#4caf50", name: "Incoming" },
outgoing: { icon: "⬆️", color: "#ffeb3b", name: "Outgoing" },
status: { icon: "ℹ️", color: "#2196f3", name: "Status" },
error: { icon: "❌", color: "#f44336", name: "Error" },
};
const { icon, color, name } = typeStyles[type];
return (
{icon}
{name}
{timestamp.toLocaleTimeString()}
{typeof payload === "object" ? (
{JSON.stringify(payload, null, 2)}
) : (
{String(payload)}
)}
);
};
export function DeltaLogViewer() {
const [open, setOpen] = useState(false);
const log = useAtomValue(logEntriesAtom);
return (
ESAV Live Log
{log.length === 0 ? (
Waiting for events...
) : (
log.map((entry) =>
)
)}
);
}