Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
hu8813 committed Apr 25, 2024
1 parent 9408dfa commit 07e38d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions srcs/backend/myapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down
10 changes: 7 additions & 3 deletions srcs/frontend/js/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function displayErrorMessage(message) {
errorMessageElement.style.fontSize = '0.6em';
}
}

async function showGameHistory() {
try {
const jwtToken = localStorage.getItem('jwtToken');
Expand All @@ -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 = `
<div><strong>Opponent:</strong> ${game.opponent || 'cpu'}</div>
<div><strong>Game Type:</strong> ${game.game_type}</div>
<div><strong>Date Played:</strong> ${game.date_time_played}</div>
<div><strong>Result:</strong>
${game.tournaments_won ? '<i class="bi bi-trophy-fill text-success fs-5"></i>' : '<i class="bi bi-emoji-frown-fill text-danger fs-5"></i>'}
</div>
`;
gameHistoryContainer.appendChild(gameElement);
});
Expand All @@ -45,7 +50,6 @@ async function showGameHistory() {
}
}


function isLocalDeployment() {
return window.location.href.includes("pong42");
}
Expand Down

0 comments on commit 07e38d2

Please sign in to comment.