diff --git a/frontend/src/pages/Stats.tsx b/frontend/src/pages/Stats.tsx index 53deb07..8e2f512 100644 --- a/frontend/src/pages/Stats.tsx +++ b/frontend/src/pages/Stats.tsx @@ -18,12 +18,19 @@ type BackendWord = { count: number; } +type TopUser = { + author: string; + source: string; + count: number; +}; + const StatPage = () => { const [error, setError] = useState(''); const [loading, setLoading] = useState(true); const [postsPerDay, setPostsPerDay] = useState([]); const [heatmapData, setHeatmapData] = useState([]); + const [topUserData, setTopUserData] = useState([]); const [wordFrequencyData, setWordFrequencyData] = useState([]); const inputRef = useRef(null); @@ -33,13 +40,18 @@ const StatPage = () => { Promise.all([ axios.get("http://localhost:5000/stats/time"), + axios.get("http://localhost:5000/stats/user"), axios.get("http://localhost:5000/stats/content"), ]) - .then(([timeRes, wordsRes]) => { + .then(([timeRes, userRes, wordsRes]) => { const eventsPerDay = Array.isArray(timeRes.data?.events_per_day) ? timeRes.data.events_per_day : []; + const topUsers = Array.isArray(userRes.data?.top_users) + ? userRes.data.top_users + : []; + const weekdayHourHeatmap = Array.isArray(timeRes.data?.weekday_hour_heatmap) ? timeRes.data.weekday_hour_heatmap : []; @@ -54,6 +66,8 @@ const StatPage = () => { ) ); + setTopUserData(topUsers); + setHeatmapData(weekdayHourHeatmap); setWordFrequencyData( @@ -62,6 +76,7 @@ const StatPage = () => { value: d.count, })) ); + }) .catch((e) => setError("Failed to load statistics: " + String(e))); }; @@ -113,18 +128,18 @@ const StatPage = () => {

Events per Day

- + @@ -151,7 +166,26 @@ const StatPage = () => { }} />
-
+ + {topUserData?.length > 0 && ( +
+

Top Users

+ {topUserData.map((item) => ( +

+ {item.author} ({item.source}): {item.count} +

+ ))} +
+ )} + +

Heatmap