Use community webhook for live stats (108 users, 27 topics)
This commit is contained in:
+45
-7
@@ -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 USER_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/user';
|
||||||
const PROFILE_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/profile';
|
const PROFILE_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/profile';
|
||||||
const WIKI_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/wiki';
|
const WIKI_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/wiki';
|
||||||
|
const COMMUNITY_URL = 'https://n8n.odoo4projects.com/webhook/paraguay/community';
|
||||||
|
|
||||||
let currentLang = 'de';
|
let currentLang = 'de';
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
currentLang = document.body.dataset.lang || 'de';
|
currentLang = document.body.dataset.lang || 'de';
|
||||||
checkSession();
|
checkSession();
|
||||||
|
loadCommunityStats();
|
||||||
|
|
||||||
// Smooth scroll nav links
|
// Smooth scroll nav links
|
||||||
document.querySelectorAll('.nav-link').forEach(link => {
|
document.querySelectorAll('.nav-link').forEach(link => {
|
||||||
@@ -113,6 +115,47 @@ function isDE() {
|
|||||||
return currentLang !== 'en';
|
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
|
// AUTH / SESSION
|
||||||
// ========================================
|
// ========================================
|
||||||
@@ -388,10 +431,7 @@ async function loadUsers() {
|
|||||||
container.appendChild(card);
|
container.appendChild(card);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update stats
|
// Update stats will be handled by loadCommunityStats
|
||||||
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;
|
|
||||||
} else {
|
} else {
|
||||||
container.innerHTML = '<p class="loading-text">' + (isDE() ? 'Keine Mitglieder gefunden' : 'No members found') + '</p>';
|
container.innerHTML = '<p class="loading-text">' + (isDE() ? 'Keine Mitglieder gefunden' : 'No members found') + '</p>';
|
||||||
}
|
}
|
||||||
@@ -462,9 +502,7 @@ async function loadWiki() {
|
|||||||
wikiData = result.data;
|
wikiData = result.data;
|
||||||
renderWikiCards(wikiData);
|
renderWikiCards(wikiData);
|
||||||
|
|
||||||
// Update stat
|
// Wiki count will be loaded from community webhook
|
||||||
const uniqueTopics = new Set(wikiData.map(w => w.topic || w.topic_en || ''));
|
|
||||||
document.getElementById('stat-wiki').textContent = uniqueTopics.size;
|
|
||||||
} else {
|
} else {
|
||||||
document.getElementById('wiki-grid').innerHTML = '<p class="loading-text">' + (isDE() ? 'Keine Wiki-Daten' : 'No wiki data') + '</p>';
|
document.getElementById('wiki-grid').innerHTML = '<p class="loading-text">' + (isDE() ? 'Keine Wiki-Daten' : 'No wiki data') + '</p>';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user