import { useEffect, useRef } from "preact/hooks"; import type { LogLine } from "../types"; interface Props { lines: LogLine[]; } export function LogPanel({ lines }: Props) { const innerRef = useRef(null); // Scroll to top (newest line — column-reverse layout) after each update useEffect(() => { const el = innerRef.current?.parentElement; if (el) el.scrollTop = 0; }, [lines]); return (
{lines.map((line) => { const time = line.timestamp ? new Date(line.timestamp).toLocaleTimeString() : ""; const role = line.role.trim().toLowerCase(); let text: string; if (role === "nanobot") { text = `[${time}] ${line.text.replace(/^(?:nanobot|napbot)\b\s*[:>-]?\s*/i, "")}`; } else { text = `[${time}] ${line.role}: ${line.text}`; } return (
{text}
); })}
); }