Spaces:
Running
Running
File size: 4,326 Bytes
0270f27 bdf6428 0270f27 bdf6428 0270f27 bdf6428 0270f27 bdf6428 0270f27 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Leaderboard - CodeFlow Typing Challenge</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
</head>
<body class="bg-gray-900 text-gray-100 min-h-screen">
<custom-header></custom-header>
<main class="container mx-auto px-4 py-8 max-w-4xl">
<div class="text-center mb-12">
<h1 class="text-4xl font-bold mb-2 text-indigo-400">Leaderboard</h1>
<p class="text-lg text-gray-400">Top typing speeds from our community</p>
</div>
<div class="bg-gray-800 rounded-xl p-6 shadow-lg mb-8">
<div id="leaderboard-container" class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-700">
<thead>
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Rank</th>
<th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Name</th>
<th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Grade & Section</th>
<th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Language</th>
<th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">WPM</th>
<th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Accuracy</th>
<th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Time</th>
<th class="px-6 py-3 text-left text-xs font-medium text-indigo-300 uppercase tracking-wider">Date</th>
</tr>
</thead>
<tbody id="leaderboard-body" class="divide-y divide-gray-700">
<!-- Leaderboard data will be inserted here -->
</tbody>
</table>
</div>
</div>
</main>
<custom-footer></custom-footer>
<script src="components/header.js"></script>
<script src="components/footer.js"></script>
<script>
feather.replace();
// Fetch and display leaderboard
async function loadLeaderboard() {
const leaderboard = await fetchLeaderboard();
const tbody = document.getElementById('leaderboard-body');
tbody.innerHTML = '';
leaderboard.forEach((entry, index) => {
const row = document.createElement('tr');
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap">${index + 1}</td>
<td class="px-6 py-4 whitespace-nowrap">${entry.name}</td>
<td class="px-6 py-4 whitespace-nowrap">${entry.grade} - ${entry.section}</td>
<td class="px-6 py-4 whitespace-nowrap">${entry.language.toUpperCase()}</td>
<td class="px-6 py-4 whitespace-nowrap">${entry.wpm}</td>
<td class="px-6 py-4 whitespace-nowrap">${entry.accuracy}%</td>
<td class="px-6 py-4 whitespace-nowrap">${entry.time_taken}s</td>
<td class="px-6 py-4 whitespace-nowrap">${new Date(entry.created_at).toLocaleString()}</td>
`;
tbody.appendChild(row);
});
}
// Call fetchLeaderboard from script.js
async function fetchLeaderboard() {
try {
const response = await fetch('db.php');
const data = await response.json();
if (data.success) {
return data.data;
}
return [];
} catch (error) {
console.error('Error fetching leaderboard:', error);
return [];
}
}
document.addEventListener('DOMContentLoaded', loadLeaderboard);
</script>
</body>
</html> |