Fix stats — API returns array, handle data[0].users/topics/posts correctly
This commit is contained in:
+11
-5
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user