import { useEffect, useState } from "react"; import { getQueryHistory } from "../api/client"; import type { QueryHistoryItem } from "../types"; interface Props { onSelect: (item: QueryHistoryItem) => void; } function relativeTime(dateStr: string): string { const diff = Date.now() - new Date(dateStr).getTime(); const mins = Math.floor(diff / 60_000); if (mins < 1) return "just now"; if (mins < 60) return `${mins}m ago`; const hours = Math.floor(mins / 60); if (hours < 24) return `${hours}h ago`; return `${Math.floor(hours / 24)}d ago`; } export default function QueryHistory({ onSelect }: Props) { const [history, setHistory] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { getQueryHistory(10) .then(setHistory) .catch(console.error) .finally(() => setLoading(false)); }, []); if (loading) { return (
{Array.from({ length: 4 }).map((_, i) => (
))}
); } if (!history.length) { return (

No queries yet

); } return (
{history.map((item) => ( ))}
); }