From 5332af57e8f461880356b3065a0dbb8aeee151d4 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Thu, 29 Jan 2026 15:02:24 +0000 Subject: [PATCH] refactor: remove unnecessay WordCloud abstraction --- frontend/src/pages/Stats.tsx | 59 +++++++++++++++++++++----------- frontend/src/stats/WordCloud.tsx | 41 ---------------------- 2 files changed, 39 insertions(+), 61 deletions(-) delete mode 100644 frontend/src/stats/WordCloud.tsx diff --git a/frontend/src/pages/Stats.tsx b/frontend/src/pages/Stats.tsx index f7ff314..1f8bfb8 100644 --- a/frontend/src/pages/Stats.tsx +++ b/frontend/src/pages/Stats.tsx @@ -9,9 +9,14 @@ import { CartesianGrid, ResponsiveContainer } from "recharts"; -import WordCloud from "../stats/WordCloud"; -import ActivityHeatmap from "../stats/ActivityHeatmap"; +import ActivityHeatmap from "../stats/ActivityHeatmap"; +import { ReactWordcloud } from '@cp949/react-wordcloud'; + +type BackendWord = { + word: string; + count: number; +} const StatPage = () => { const [data, setData] = useState([]); @@ -19,31 +24,45 @@ const StatPage = () => { const [loading, setLoading] = useState(true); 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("2025-06-01"))); - setLoading(false); - }) - .catch(err => { - setError(err.response?.data?.error || "Failed to load data"); - setLoading(false); + .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); + 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); + }); }, []); if (loading) return

Loading posts per day…

; @@ -68,7 +87,7 @@ const StatPage = () => {

Word Cloud

- +

Heatmap

diff --git a/frontend/src/stats/WordCloud.tsx b/frontend/src/stats/WordCloud.tsx deleted file mode 100644 index 5477053..0000000 --- a/frontend/src/stats/WordCloud.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { ReactWordcloud } from '@cp949/react-wordcloud'; -import { useEffect, useState } from 'react'; -import axios from "axios"; - -type BackendWord = { - word: string; - count: number; -} - -const WordCloud = () => { - const [words, setWords] = useState<{ text: string; value: number }[]>([]); - const [error, setError] = useState(''); - - - useEffect(() => { - axios - .get("http://localhost:5000/stats/word_frequencies") - .then(res => { - const mapped = res.data.map((d: BackendWord) => ( - {text: d.word, value: d.count} - )); - setWords(mapped); - }) - .catch(err => { - setError(err); - }); - - }, []) - - return ( -
- - -

{error}

-
- ); -}; - -export default WordCloud; \ No newline at end of file