import { VSCodeButton } from "@vscode/webview-ui-toolkit/react" import { useExtensionState } from "../context/ExtensionStateContext" import { vscode } from "../utils/vscode" import { memo } from "react" type HistoryPreviewProps = { showHistoryView: () => void } const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => { const { taskHistory } = useExtensionState() const handleHistorySelect = (id: string) => { vscode.postMessage({ type: "showTaskWithId", text: id }) } const formatDate = (timestamp: number) => { const date = new Date(timestamp) return date ?.toLocaleString("en-US", { month: "long", day: "numeric", hour: "numeric", minute: "2-digit", hour12: true, }) .replace(", ", " ") .replace(" at", ",") .toUpperCase() } return (
Recent Tasks
{taskHistory .filter((item) => item.ts && item.task) .slice(0, 3) .map((item) => (
handleHistorySelect(item.id)}>
{formatDate(item.ts)}
{item.task}
Tokens: ↑{item.tokensIn?.toLocaleString()} ↓{item.tokensOut?.toLocaleString()} {!!item.cacheWrites && ( <> {" • "} Cache: +{item.cacheWrites?.toLocaleString()} →{" "} {(item.cacheReads || 0).toLocaleString()} )} {!!item.totalCost && ( <> {" • "} API Cost: ${item.totalCost?.toFixed(4)} )}
))}
showHistoryView()} style={{ opacity: 0.9, }}>
View all history
) } export default memo(HistoryPreview)