'use client'; import { useEffect, useState } from 'react'; import Link from 'next/link'; import { formatMinutes } from '@/lib/steam'; interface MapSummary { map_name: string; times_played: number; last_played: string; total_minutes: number; } export default function MapSearch() { const [q, setQ] = useState(''); const [maps, setMaps] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const handle = setTimeout(async () => { setLoading(true); const res = await fetch(`/api/maps?q=${encodeURIComponent(q)}`); const data = await res.json(); setMaps(data.maps); setLoading(false); }, 250); return () => clearTimeout(handle); }, [q]); return (
setQ(e.target.value)} className="w-full bg-base-panel border border-base-border rounded-lg px-4 py-3 text-ink placeholder:text-ink-faint focus:border-accent/50 transition-colors" />
{loading ? (
loading…
) : maps.length === 0 ? (
No maps found.
) : ( maps.map((m) => (
{m.map_name}
{m.times_played}× played · {formatMinutes(m.total_minutes)} total last played {new Date(m.last_played.replace(' ', 'T')).toLocaleString()}
)) )}
); }