From 697788c20fd2d771d28271c2a13e9848cdfacb8b Mon Sep 17 00:00:00 2001 From: Rene Luria Date: Tue, 19 Aug 2025 19:21:50 +0200 Subject: [PATCH] feat: auto-load events on login and improve player display in event details - Automatically load events when user logs in - Rename updateAccountOptions to updateAccountOptionsAndLoadEvents - Add auto-fetch of events after account selection - Enhance event details modal with: * Player count summary * Position breakdown * Players sorted by position first, then by number * Position displayed in player list --- index.html | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/index.html b/index.html index 517e68d..ce395cc 100644 --- a/index.html +++ b/index.html @@ -210,9 +210,7 @@ } eventFilters.style.display = "block"; - updateAccountOptions(); - // Don't automatically fetch events on page load - // Wait for user to explicitly select an account or click fetch + updateAccountOptionsAndLoadEvents(); } else { // User is not logged in loginView.style.display = "flex"; @@ -255,7 +253,7 @@ location.reload(); } - function updateAccountOptions() { + function updateAccountOptionsAndLoadEvents() { // Fetch available accounts from the server fetch(`${apiBaseUrl}/accounts`, { headers: { "Authorization": `Bearer ${storedApiKey}` } @@ -306,6 +304,9 @@ // Set the selected account in the dropdown accountSelect.value = accountToSelect; + + // Automatically fetch events for the selected account + fetchEvents(storedApiKey, accountToSelect); }) .catch(error => { console.error("Erreur lors du chargement des comptes:", error); @@ -453,16 +454,46 @@ const sortedPlayers = data.convocation.available .sort((a, b) => (a.number || 0) - (b.number || 0)); + // Calculate player statistics + const totalPlayers = sortedPlayers.length; + const positionCount = {}; + sortedPlayers.forEach(player => { + const position = player.position || "N/A"; + positionCount[position] = (positionCount[position] || 0) + 1; + }); + + // Generate position breakdown + const positionBreakdown = Object.entries(positionCount) + .map(([position, count]) => `${position}: ${count}`) + .join(', '); + + // Sort players by position first, then by number + const playersByPosition = [...sortedPlayers].sort((a, b) => { + // Sort by position first + const positionA = a.position || "ZZZ"; // Put undefined positions at the end + const positionB = b.position || "ZZZ"; + + if (positionA !== positionB) { + return positionA.localeCompare(positionB); + } + + // If positions are the same, sort by number + const numA = parseInt(a.number) || 0; + const numB = parseInt(b.number) || 0; + return numA - numB; + }); + eventDetailsContent.innerHTML = `
${data.title}

Type: ${data.type}

Lieu: ${data.place}

Heure: ${data.time_start} - ${data.time_end}

-
Joueurs convoqués:
-