diff --git a/frontend/src/pages/Stats.tsx b/frontend/src/pages/Stats.tsx index 1f8bfb8..2cbfe0d 100644 --- a/frontend/src/pages/Stats.tsx +++ b/frontend/src/pages/Stats.tsx @@ -19,61 +19,46 @@ type BackendWord = { } const StatPage = () => { - const [data, setData] = useState([]); - const [error, setError] = useState(null); + const [error, setError] = useState(''); const [loading, setLoading] = useState(true); + const [postsPerDay, setPostsPerDay] = useState([]); const [heatmapData, setHeatmapData] = useState([]); const [wordFrequencyData, setWordFrequencyData] = useState([]); useEffect(() => { - // Posts per Day - axios - .get("http://localhost:5000/stats/events_per_day") - .then(res => { - setData(res.data.filter((item: any) => new Date(item.date) >= new Date("2026-01-10"))); - setLoading(false); - }) - .catch(err => { - setError(err.response?.data?.error || "Failed to load data"); - setLoading(false); - }); - - // Heatmap - axios - .get("http://localhost:5000/stats/heatmap") - .then(res => { - setHeatmapData(res.data); - setLoading(false); - }) - .catch(err => { - setError(err.response?.data?.error || "Failed to load heatmap data"); - setLoading(false); - }); - - // Word Frequencies - axios - .get("http://localhost:5000/stats/word_frequencies") - .then(res => { - const mapped = res.data.map((d: BackendWord) => ( - {text: d.word, value: d.count} - )); - setWordFrequencyData(mapped); - }) - .catch(err => { - setError(err); - }); + Promise.all([ + axios.get("http://localhost:5000/stats/events_per_day"), + axios.get("http://localhost:5000/stats/heatmap"), + axios.get("http://localhost:5000/stats/word_frequencies"), + ]) + .then(([eventsRes, heatmapRes, wordsRes]) => { + setPostsPerDay( + eventsRes.data.filter( + (d: any) => new Date(d.date) >= new Date("2026-01-10") + ) + ); + setHeatmapData(heatmapRes.data); + setWordFrequencyData( + wordsRes.data.map((d: BackendWord) => ({ + text: d.word, + value: d.count, + })) + ); + }) + .catch(() => setError("Failed to load statistics")) + .finally(() => setLoading(false)); }, []); - if (loading) return

Loading posts per day…

; - if (error) return

{error}

; + if (loading) return

Loading insights…

; + if (error) return

{error}

; return (

Posts per Day

- + diff --git a/frontend/src/stats/ActivityHeatmap.tsx b/frontend/src/stats/ActivityHeatmap.tsx index bc5625c..903174f 100644 --- a/frontend/src/stats/ActivityHeatmap.tsx +++ b/frontend/src/stats/ActivityHeatmap.tsx @@ -51,7 +51,7 @@ const ActivityHeatmap = ({ data }: ActivityHeatmapProps) => { ); return ( -