From 07e38d231e10361f4367111794b8866c70a629f3 Mon Sep 17 00:00:00 2001 From: kaya Date: Thu, 25 Apr 2024 16:19:44 +0200 Subject: [PATCH] a --- srcs/backend/myapp/views.py | 1 + srcs/frontend/js/Profile.js | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) 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 = `
Opponent: ${game.opponent || 'cpu'}
Game Type: ${game.game_type}
Date Played: ${game.date_time_played}
+
Result: + ${game.tournaments_won ? '' : ''} +
`; gameHistoryContainer.appendChild(gameElement); }); @@ -45,7 +50,6 @@ async function showGameHistory() { } } - function isLocalDeployment() { return window.location.href.includes("pong42"); }