summaryrefslogtreecommitdiff
path: root/lambda-calcul/haskell/public/leaderboard.js
blob: b1ba07ad684d2efef528fac20309dadb1b2b51e3 (plain)
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
const updateLeaderboard = () => {
  const rows = document.querySelectorAll('table#leaderboard > tbody > tr');

  rows.forEach(row => {
    row.remove();
  });

  fetch('/api/leaderboard')
    .then(response => response.json())
    .then(data => {
      const tbody = document.querySelector('table#leaderboard > tbody');

      data.forEach((entry, index) => {
        const row = document.createElement('tr');

        const nameCell = document.createElement('td');
        nameCell.textContent = entry.user;
        row.appendChild(nameCell);

        const scoreCell = document.createElement('td');
        scoreCell.textContent = entry.grade;
        row.appendChild(scoreCell);

        const timeCell = document.createElement('td');
        timeCell.textContent = entry.lastTest;
        row.appendChild(timeCell);

        tbody.appendChild(row);
      });
    })
    .catch(error => {
      console.error('Error fetching leaderboard data:', error);
    });
};

document.addEventListener('DOMContentLoaded', () => {
  setInterval(updateLeaderboard, 5000);
});