This commit is contained in:
kacper 2026-03-06 22:51:19 -05:00
parent 6acf267d48
commit b7614eb3f8
4794 changed files with 1280808 additions and 1546 deletions

View file

@ -0,0 +1,38 @@
import { useEffect, useRef } from "preact/hooks";
import type { LogLine } from "../types";
interface Props {
lines: LogLine[];
}
export function LogPanel({ lines }: Props) {
const innerRef = useRef<HTMLDivElement>(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 (
<div id="log">
<div id="log-inner" ref={innerRef}>
{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 (
<div key={line.id} class={`line ${line.role}`}>
{text}
</div>
);
})}
</div>
</div>
);
}