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 { try {
const response = await fetch(COMMUNITY_URL); const response = await fetch(COMMUNITY_URL);
if (!response.ok) throw new Error('Failed to fetch'); if (!response.ok) throw new Error('Failed to fetch');
const data = await response.json(); const json = await response.json();
if (data.users !== undefined) { // API returns an array: [{"users": 4, "topics": 27, "posts": 58}]
animateCounter('stat-members', data.users); const d = Array.isArray(json) ? json[0] : json;
if (d.users !== undefined) {
animateCounter('stat-members', d.users);
} }
if (data.topics !== undefined) { if (d.posts !== undefined) {
document.getElementById('stat-wiki').textContent = data.topics; animateCounter('stat-posts', d.posts);
}
if (d.topics !== undefined) {
animateCounter('stat-wiki', d.topics);
} }
} catch (error) { } catch (error) {
console.error('Failed to load community stats:', error); console.error('Failed to load community stats:', error);