From 6cd4319fcf540ef70f74cc2f10d0d4297ee7b788 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Thu, 11 Apr 2024 16:59:01 +0100 Subject: feat(gui): add base structure (#1935) * initial * ui things * cargo * update, add history refresh button * history page a bit better, add initial dotfiles page * re-org layout * bye squigglies * add dotfiles ui, show aliases * add default shell detection * put stats in a little drawer, alias import changes * use new table for aliases, add alias deleting * support adding aliases * close drawer when added, no alias autocomplete * clippy, format * attempt to ensure gdk is installed ok * sudo * no linux things on mac ffs * I forgot we build for windows too... end of day * remove tauri backend from workspace --- ui/src/components/history/Stats.tsx | 143 ++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 ui/src/components/history/Stats.tsx (limited to 'ui/src/components/history') diff --git a/ui/src/components/history/Stats.tsx b/ui/src/components/history/Stats.tsx new file mode 100644 index 00000000..afd9ed89 --- /dev/null +++ b/ui/src/components/history/Stats.tsx @@ -0,0 +1,143 @@ +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. */} + +
+
+ +
+ +
+ + + + + + + + +
+
+
+ ); +} -- cgit v1.3.1