Fix stats — API returns array, handle data[0].users/topics/posts correctly

This commit is contained in:
Kato
2026-09-05 12:02:55 +00:00
parent a23b9f722b
commit 36be3a56f6
+11 -5
View File
@@ -122,13 +122,19 @@ async function loadCommunityStats() {
try {
const response = await fetch(COMMUNITY_URL);
if (!response.ok) throw new Error('Failed to fetch');
const data = await response.json();
const json = await response.json();
if (data.users !== undefined) {
animateCounter('stat-members', data.users);
// API returns an array: [{"users": 4, "topics": 27, "posts": 58}]
const d = Array.isArray(json) ? json[0] : json;
if (d.users !== undefined) {
animateCounter('stat-members', d.users);
}
if (data.topics !== undefined) {
document.getElementById('stat-wiki').textContent = data.topics;
if (d.posts !== undefined) {
animateCounter('stat-posts', d.posts);
}
if (d.topics !== undefined) {
animateCounter('stat-wiki', d.topics);
}
} catch (error) {
console.error('Failed to load community stats:', error);