diff --git a/srcs/backend/myapp/views.py b/srcs/backend/myapp/views.py index cfaeb17..1ddce87 100644 --- a/srcs/backend/myapp/views.py +++ b/srcs/backend/myapp/views.py @@ -331,6 +331,7 @@ def fetch_game_history(request): game_history_data.append({ 'opponent': achievement.opponent, 'game_type': achievement.game_type, + 'tournaments_won': achievement.tournaments_won, 'date_time_played': achievement.date_time_played.strftime('%Y-%m-%d %H:%M:%S') # Convert to string }) diff --git a/srcs/frontend/js/Profile.js b/srcs/frontend/js/Profile.js index 67a175b..9dfd195 100644 --- a/srcs/frontend/js/Profile.js +++ b/srcs/frontend/js/Profile.js @@ -7,7 +7,6 @@ function displayErrorMessage(message) { errorMessageElement.style.fontSize = '0.6em'; } } - async function showGameHistory() { try { const jwtToken = localStorage.getItem('jwtToken'); @@ -26,13 +25,19 @@ async function showGameHistory() { const gameHistoryContainer = document.getElementById('gameHistory'); gameHistoryContainer.innerHTML = ''; + // Sort game history by date_time_played in descending order + gameHistoryData.sort((a, b) => new Date(b.date_time_played) - new Date(a.date_time_played)); + gameHistoryData.forEach(game => { const gameElement = document.createElement('div'); - gameElement.classList.add('game-item'); + gameElement.classList.add('game-item', 'mb-3', 'border', 'border-primary', 'rounded', 'p-3'); gameElement.innerHTML = `