import { type Component, For, Show, createEffect, on } from "solid-js"; import type { CommanderEntry } from "./types"; import { getResultClass } from "./hooks"; export interface CommanderEntriesProps { entries: () => CommanderEntry[]; onCommandClick?: (command: string) => void; } export const CommanderEntries: Component = (props) => { let containerRef: HTMLDivElement | undefined; // 当 entries 变化时自动滚动到底部 createEffect( on( () => props.entries().length, () => { if (containerRef) { containerRef.scrollTop = containerRef.scrollHeight; } }, ), ); const handleCommandClick = (command: string) => { if (props.onCommandClick) { props.onCommandClick(command); } }; return (
0} fallback={
暂无命令执行记录
} > {(entry) => (
handleCommandClick(entry.command)} title="点击复制到输入框" > {entry.command} {entry.timestamp.toLocaleTimeString()}
{!entry.result.isHtml && entry.result.message}
)}
); };