From 36be3a56f67a11577c8679fa629b9029d94c10ac Mon Sep 17 00:00:00 2001 From: Kato Date: Sat, 5 Sep 2026 12:02:55 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20stats=20=E2=80=94=20API=20returns=20array?= =?UTF-8?q?,=20handle=20data[0].users/topics/posts=20correctly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/main.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/js/main.js b/js/main.js index 667dad7..d054f76 100644 --- a/js/main.js +++ b/js/main.js @@ -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);