diff --git a/js/main.js b/js/main.js index 2f1f8d8..667dad7 100644 --- a/js/main.js +++ b/js/main.js @@ -7,12 +7,14 @@ const NEWSLETTER_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/newslette const USER_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/user'; const PROFILE_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/profile'; const WIKI_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/wiki'; +const COMMUNITY_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/community'; let currentLang = 'de'; document.addEventListener('DOMContentLoaded', () => { currentLang = document.body.dataset.lang || 'de'; checkSession(); + loadCommunityStats(); // Smooth scroll nav links document.querySelectorAll('.nav-link').forEach(link => { @@ -113,6 +115,47 @@ function isDE() { return currentLang !== 'en'; } +// ======================================== +// COMMUNITY STATS +// ======================================== +async function loadCommunityStats() { + try { + const response = await fetch(COMMUNITY_URL); + if (!response.ok) throw new Error('Failed to fetch'); + const data = await response.json(); + + if (data.users !== undefined) { + animateCounter('stat-members', data.users); + } + if (data.topics !== undefined) { + document.getElementById('stat-wiki').textContent = data.topics; + } + } catch (error) { + console.error('Failed to load community stats:', error); + } +} + +function animateCounter(elementId, targetNumber) { + const element = document.getElementById(elementId); + if (!element) return; + + let current = 0; + const duration = 1500; // ms + const steps = 40; + const increment = targetNumber / steps; + const stepTime = duration / steps; + + const timer = setInterval(() => { + current += increment; + if (current >= targetNumber) { + element.textContent = targetNumber; + clearInterval(timer); + } else { + element.textContent = Math.floor(current); + } + }, stepTime); +} + // ======================================== // AUTH / SESSION // ======================================== @@ -388,10 +431,7 @@ async function loadUsers() { container.appendChild(card); }); - // Update stats - document.getElementById('stat-members').textContent = data.data.length; - const totalPosts = data.data.reduce((sum, u) => sum + (u.posts || 0), 0); - document.getElementById('stat-posts').textContent = totalPosts; + // Update stats will be handled by loadCommunityStats } else { container.innerHTML = '
' + (isDE() ? 'Keine Mitglieder gefunden' : 'No members found') + '
'; } @@ -462,9 +502,7 @@ async function loadWiki() { wikiData = result.data; renderWikiCards(wikiData); - // Update stat - const uniqueTopics = new Set(wikiData.map(w => w.topic || w.topic_en || '')); - document.getElementById('stat-wiki').textContent = uniqueTopics.size; + // Wiki count will be loaded from community webhook } else { document.getElementById('wiki-grid').innerHTML = '' + (isDE() ? 'Keine Wiki-Daten' : 'No wiki data') + '
'; }