refactor: remove unnecessay WordCloud abstraction
This commit is contained in:
@@ -9,9 +9,14 @@ import {
|
|||||||
CartesianGrid,
|
CartesianGrid,
|
||||||
ResponsiveContainer
|
ResponsiveContainer
|
||||||
} from "recharts";
|
} 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 StatPage = () => {
|
||||||
const [data, setData] = useState([]);
|
const [data, setData] = useState([]);
|
||||||
@@ -19,31 +24,45 @@ const StatPage = () => {
|
|||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const [heatmapData, setHeatmapData] = useState([]);
|
const [heatmapData, setHeatmapData] = useState([]);
|
||||||
|
const [wordFrequencyData, setWordFrequencyData] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Posts per Day
|
// Posts per Day
|
||||||
axios
|
axios
|
||||||
.get("http://localhost:5000/stats/events_per_day")
|
.get("http://localhost:5000/stats/events_per_day")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
setData(res.data.filter((item: any) => new Date(item.date) >= new Date("2025-06-01")));
|
setData(res.data.filter((item: any) => new Date(item.date) >= new Date("2026-01-10")));
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
setError(err.response?.data?.error || "Failed to load data");
|
setError(err.response?.data?.error || "Failed to load data");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Heatmap
|
// Heatmap
|
||||||
axios
|
axios
|
||||||
.get("http://localhost:5000/stats/heatmap")
|
.get("http://localhost:5000/stats/heatmap")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
setHeatmapData(res.data);
|
setHeatmapData(res.data);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
setError(err.response?.data?.error || "Failed to load heatmap data");
|
setError(err.response?.data?.error || "Failed to load heatmap data");
|
||||||
setLoading(false);
|
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 <p>Loading posts per day…</p>;
|
if (loading) return <p>Loading posts per day…</p>;
|
||||||
@@ -68,7 +87,7 @@ const StatPage = () => {
|
|||||||
</ResponsiveContainer>
|
</ResponsiveContainer>
|
||||||
|
|
||||||
<h2>Word Cloud</h2>
|
<h2>Word Cloud</h2>
|
||||||
<WordCloud />
|
<ReactWordcloud words={wordFrequencyData}/>
|
||||||
|
|
||||||
<h2>Heatmap</h2>
|
<h2>Heatmap</h2>
|
||||||
<ActivityHeatmap data={heatmapData} />
|
<ActivityHeatmap data={heatmapData} />
|
||||||
|
|||||||
@@ -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<string>('');
|
|
||||||
|
|
||||||
|
|
||||||
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 (
|
|
||||||
<div>
|
|
||||||
<ReactWordcloud
|
|
||||||
words={words}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<p>{error}</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default WordCloud;
|
|
||||||
Reference in New Issue
Block a user