"use client"; import { useState, useEffect } from "react"; type Stats = { total: number; pinned: number; latest: string | null; colors: { color: string; count: number }[] }; export default function StatsBar() { const [stats, setStats] = useState(null); const [ms, setMs] = useState(null); useEffect(() => { fetch("/api/stats").then((r) => r.json()).then((j) => { if (j.ok) { setStats(j.data); setMs(j.ms ?? null); } }); }, []); if (!stats) return null; return (
📊 {stats.total} notes 📌 {stats.pinned} pinned {stats.latest && 🕐 {new Date(stats.latest).toLocaleString()}} {ms !== null && ( ⚡ {ms}ms )}
{stats.colors.map((c) => ( ))}
); }