add spinner

This commit is contained in:
quoije
2025-01-29 19:06:29 -05:00
parent 64f390fd7d
commit eb6137e002
2 changed files with 14 additions and 7 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

+14 -7
View File
@@ -59,8 +59,14 @@
<div class="container mt-5"> <div class="container mt-5">
<h2>Statistiques des utilisateurs</h2> <h2>Statistiques des utilisateurs</h2>
<!-- Spinner shown while loading -->
<div id="loading-spinner" class="spinner-border text-primary" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<!-- Table for users and movies watched --> <!-- Table for users and movies watched -->
<table class="table user-table"> <table class="table user-table" style="display: none;">
<thead> <thead>
<tr> <tr>
<th scope="col">Nom</th> <th scope="col">Nom</th>
@@ -92,6 +98,7 @@
</div> </div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
<script> <script>
window.onload = async function () { window.onload = async function () {
const token = localStorage.getItem('auth_token'); const token = localStorage.getItem('auth_token');
@@ -125,7 +132,6 @@
} }
try { try {
// Fetch user stats from the new endpoint
const statsRes = await fetch('/api/users/stats', { const statsRes = await fetch('/api/users/stats', {
method: 'GET', method: 'GET',
headers: { headers: {
@@ -139,11 +145,11 @@
const stats = await statsRes.json(); const stats = await statsRes.json();
const userTableBody = document.getElementById('user-table-body'); const userTableBody = document.getElementById('user-table-body');
const table = document.querySelector('.user-table');
const spinner = document.getElementById('loading-spinner');
// Populate table rows with user stats
stats.forEach(userStat => { stats.forEach(userStat => {
const userRow = document.createElement('tr'); const userRow = document.createElement('tr');
userRow.innerHTML = ` userRow.innerHTML = `
<td> <td>
<a href="#" class="user-link" data-movies='${JSON.stringify(userStat.watchedMovies)}'>${userStat.name}</a> <a href="#" class="user-link" data-movies='${JSON.stringify(userStat.watchedMovies)}'>${userStat.name}</a>
@@ -151,10 +157,13 @@
<td>${userStat.watchedCount}</td> <td>${userStat.watchedCount}</td>
<td>${userStat.watchedRatio}</td> <td>${userStat.watchedRatio}</td>
`; `;
userTableBody.appendChild(userRow); userTableBody.appendChild(userRow);
}); });
// Hide spinner and show table after loading
spinner.style.display = 'none';
table.style.display = 'table';
// Add event listener for user links // Add event listener for user links
document.querySelectorAll('.user-link').forEach(link => { document.querySelectorAll('.user-link').forEach(link => {
link.addEventListener('click', function (event) { link.addEventListener('click', function (event) {
@@ -182,8 +191,6 @@
}); });
} catch (error) { } catch (error) {
console.error('Error loading user statistics:', error); console.error('Error loading user statistics:', error);
// localStorage.removeItem('auth_token');
// window.location.href = '/';
} }
// Log-off functionality // Log-off functionality