import { useState, useEffect } from "react"; import { invoke } from "@tauri-apps/api/core"; import PacmanLoader from "react-spinners/PacmanLoader"; import { BarChart, Bar, Rectangle, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, } from "recharts"; const tabs = [ { name: "Daily", href: "#", current: true }, { name: "Weekly", href: "#", current: false }, { name: "Monthly", href: "#", current: false }, ]; function classNames(...classes) { return classes.filter(Boolean).join(" "); } function renderLoading() {
; } export default function Stats() { const [stats, setStats]: any = useState([]); const [chart, setChart]: any = useState([]); console.log("Stats mounted"); 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: "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); }) .catch((e) => { console.log(e); }); }, []); if (stats.length == 0) { return renderLoading(); } return (
{stats.map((item) => (
{item.name}
{item.stat}
))}
{/* Use an "onChange" listener to redirect the user to the selected tab URL. */}
); }