import { useState, useEffect } from "react"; import { invoke } from "@tauri-apps/api/core"; import PacmanLoader from "react-spinners/PacmanLoader"; import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, } from "recharts"; function renderLoading() { return (
); } function TopTable({ stats }: any) { return (

Top commands

{stats.map((stat: any) => ( ))}
Command Count
{stat[0][0]} {stat[1]}
); } export default function Stats() { const [stats, setStats]: any = useState([]); const [top, setTop]: any = useState([]); const [chart, setChart]: any = useState([]); useEffect(() => { if (stats.length != 0) return; invoke("global_stats") .then((s: any) => { console.log(s.daily); setStats([ { name: "Total history", stat: s.total_history.toLocaleString(), }, { name: "Unique history", stat: s.stats.unique_commands.toLocaleString(), }, { name: "Last 1d", stat: s.last_1d.toLocaleString(), }, { name: "Last 7d", stat: s.last_7d.toLocaleString(), }, { name: "Last 30d", stat: s.last_30d.toLocaleString(), }, ]); setChart(s.daily); setTop(s.stats); }) .catch((e) => { console.log(e); }); }, []); if (stats.length == 0) { return renderLoading(); } return (
{stats.map((item: any) => (
{item.name}
{item.stat}
))}
); }