Add loading indicators to user statistics page
Co-authored-by: mathieumoran1 <[email protected]>
This commit is contained in:
co-authored by
mathieumoran1
parent
e318e25ed1
commit
762f75ad62
@@ -3,6 +3,24 @@ window.onload = async function () {
|
||||
let winnersCache = null;
|
||||
let completionsCache = null;
|
||||
|
||||
function setTableBodyLoading(tbodyId, colspan) {
|
||||
const tbody = document.getElementById(tbodyId);
|
||||
if (!tbody) return;
|
||||
const span = Number.isFinite(Number(colspan)) ? Number(colspan) : 1;
|
||||
tbody.innerHTML = `
|
||||
<tr>
|
||||
<td colspan="${span}" class="text-center py-4" aria-live="polite" aria-busy="true">
|
||||
<div class="d-inline-flex align-items-center gap-2">
|
||||
<div class="spinner-border text-secondary" role="status" aria-label="Chargement">
|
||||
<span class="visually-hidden">Chargement...</span>
|
||||
</div>
|
||||
<span class="text-muted">Chargement…</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
}
|
||||
|
||||
async function fetchActiveYear() {
|
||||
try {
|
||||
const res = await fetch('/api/settings/year', { method: 'GET' });
|
||||
@@ -229,6 +247,16 @@ window.onload = async function () {
|
||||
}
|
||||
|
||||
try {
|
||||
// Show loading states immediately (avoid "blank" panels)
|
||||
const table = document.querySelector('.user-table');
|
||||
const spinner = document.getElementById('loading-spinner');
|
||||
const statsError = document.getElementById('stats-error');
|
||||
if (spinner) spinner.classList.remove('d-none');
|
||||
if (table) table.classList.add('d-none');
|
||||
if (statsError) statsError.classList.add('d-none');
|
||||
setTableBodyLoading('winners-table-body', 2);
|
||||
setTableBodyLoading('completers-table-body', 4);
|
||||
|
||||
const activeYear = await fetchActiveYear();
|
||||
if (activeYear) {
|
||||
document.title = `Pool Oscars ${activeYear} - Statistiques des utilisateurs`;
|
||||
@@ -257,9 +285,6 @@ window.onload = async function () {
|
||||
|
||||
const stats = await statsRes.json();
|
||||
const userTableBody = document.getElementById('user-table-body');
|
||||
const table = document.querySelector('.user-table');
|
||||
const spinner = document.getElementById('loading-spinner');
|
||||
const statsError = document.getElementById('stats-error');
|
||||
|
||||
// Ensure watchedRatio is treated as a number and sort in descending order
|
||||
stats.sort((a, b) => parseFloat(b.watchedRatio) - parseFloat(a.watchedRatio));
|
||||
|
||||
+20
-4
@@ -91,8 +91,10 @@
|
||||
<div id="stats-error" class="alert alert-danger d-none" role="alert"></div>
|
||||
|
||||
<!-- Spinner shown while loading -->
|
||||
<div id="loading-spinner" class="spinner-border text-primary" role="status">
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
<div id="loading-spinner" class="d-flex justify-content-center align-items-center my-5" aria-live="polite" aria-busy="true">
|
||||
<div class="spinner-border text-secondary" role="status" aria-label="Chargement">
|
||||
<span class="visually-hidden">Chargement...</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Table for users and movies watched -->
|
||||
@@ -123,7 +125,14 @@
|
||||
</thead>
|
||||
<tbody id="winners-table-body">
|
||||
<tr>
|
||||
<td colspan="2" class="text-muted">Chargement…</td>
|
||||
<td colspan="2" class="text-center py-4" aria-live="polite" aria-busy="true">
|
||||
<div class="d-inline-flex align-items-center gap-2">
|
||||
<div class="spinner-border text-secondary" role="status" aria-label="Chargement">
|
||||
<span class="visually-hidden">Chargement...</span>
|
||||
</div>
|
||||
<span class="text-muted">Chargement…</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -146,7 +155,14 @@
|
||||
</thead>
|
||||
<tbody id="completers-table-body">
|
||||
<tr>
|
||||
<td colspan="4" class="text-muted">Chargement…</td>
|
||||
<td colspan="4" class="text-center py-4" aria-live="polite" aria-busy="true">
|
||||
<div class="d-inline-flex align-items-center gap-2">
|
||||
<div class="spinner-border text-secondary" role="status" aria-label="Chargement">
|
||||
<span class="visually-hidden">Chargement...</span>
|
||||
</div>
|
||||
<span class="text-muted">Chargement…</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user