From cc63e8429e87959e9f747c7100dbaa2b874ce515 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Sun, 1 Feb 2026 16:16:44 +0000 Subject: [PATCH] feat: add search bar to Stat page --- frontend/src/pages/Stats.tsx | 44 +++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/Stats.tsx b/frontend/src/pages/Stats.tsx index b20d01a..e1fe123 100644 --- a/frontend/src/pages/Stats.tsx +++ b/frontend/src/pages/Stats.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useEffect, useState, useRef } from "react"; import axios from "axios"; import { LineChart, @@ -26,7 +26,9 @@ const StatPage = () => { const [heatmapData, setHeatmapData] = useState([]); const [wordFrequencyData, setWordFrequencyData] = useState([]); - useEffect(() => { + const inputRef = useRef(null); + + const getStats = () => { Promise.all([ axios.get("http://localhost:5000/stats/time"), axios.get("http://localhost:5000/stats/content"), @@ -48,13 +50,48 @@ const StatPage = () => { }) .catch((e) => setError("Failed to load statistics: " + e)) .finally(() => setLoading(false)); - }, []); + }; + + const onSearch = () => { + const query = inputRef.current?.value ?? ""; // read input only on click + axios.post("http://localhost:5000/filter/search", { + query: query + }) + .then(() => { + getStats(); + }) + .catch(e => { + setError(e); + }) + }; + + const resetFilters = () => { + axios.get("http://localhost:5000/filter/reset") + .then(() => { + getStats(); + }) + .catch(e => { + setError(e); + }) + }; + + useEffect(getStats, []) if (loading) return

Loading insights…

; if (error) return

{error}

; return (
+ + + + + +
{ width: "100%" }} > +

Events per Day