From e061e1e9f777627d393c2dac7302d199a444b136 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Mon, 30 Mar 2026 21:31:06 -0700 Subject: [PATCH] feat: add tournaments participated and recent matches to player profile --- src/app/players/[id]/profile/page.tsx | 199 ++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/src/app/players/[id]/profile/page.tsx b/src/app/players/[id]/profile/page.tsx index c4067a8..6aa17b5 100644 --- a/src/app/players/[id]/profile/page.tsx +++ b/src/app/players/[id]/profile/page.tsx @@ -35,6 +35,40 @@ export default async function PlayerProfilePage({ params }: PageProps) { orderBy: { gamesPlayed: "desc" }, }) + // Get tournaments participated in + const tournaments = await prisma.event.findMany({ + where: { + participants: { + some: { + playerId: playerId, + }, + }, + }, + orderBy: { eventDate: "desc" }, + take: 10, + }) + + // Get recent matches (last 10 games played) + const recentMatches = await prisma.match.findMany({ + where: { + OR: [ + { team1P1Id: playerId }, + { team1P2Id: playerId }, + { team2P1Id: playerId }, + { team2P2Id: playerId }, + ], + }, + include: { + team1P1: true, + team1P2: true, + team2P1: true, + team2P2: true, + event: true, + }, + orderBy: { playedAt: "desc" }, + take: 10, + }) + // Use direct player stats for overall statistics (more accurate and consistent with rankings page) const totalGames = player.gamesPlayed const totalWins = player.wins @@ -95,6 +129,171 @@ export default async function PlayerProfilePage({ params }: PageProps) { + {/* Tournaments Participated */} +
+

+ Tournaments Participated +

+ + {tournaments.length === 0 ? ( +

No tournament data available yet.

+ ) : ( +
+ + + + + + + + + + + {tournaments.map((tournament) => ( + + + + + + + ))} + +
+ Tournament + + Date + + Format + + Status +
+ + {tournament.name} + + + {tournament.eventDate + ? new Date(tournament.eventDate).toLocaleDateString() + : "N/A"} + + {tournament.format} + + + {tournament.status} + +
+
+ )} +
+ + {/* Recent Games */} +
+

+ Recent Games +

+ + {recentMatches.length === 0 ? ( +

No game data available yet.

+ ) : ( +
+ + + + + + + + + + + + + {recentMatches.map((match) => { + const isTeam1 = match.team1P1Id === playerId || match.team1P2Id === playerId; + const teamWon = isTeam1 ? match.team1Score > match.team2Score : match.team2Score > match.team1Score; + const teamScore = isTeam1 ? match.team1Score : match.team2Score; + const opponentScore = isTeam1 ? match.team2Score : match.team1Score; + + const teammate = isTeam1 + ? (match.team1P1Id === playerId ? match.team1P2 : match.team1P1) + : (match.team2P1Id === playerId ? match.team2P2 : match.team2P1); + + const opponents = isTeam1 + ? [match.team2P1, match.team2P2] + : [match.team1P1, match.team1P2]; + + return ( + + + + + + + + + ) + })} + +
+ Date + + Tournament + + Team + + Opponents + + Score + + Result +
+ {match.playedAt + ? new Date(match.playedAt).toLocaleDateString() + : "N/A"} + + {match.event?.name || "N/A"} + + + {teammate.name} + + + {opponents.map((opponent, index) => ( + + + {opponent.name} + + {index < opponents.length - 1 ? ", " : ""} + + ))} + + {teamScore} - {opponentScore} + + + {teamWon ? 'Win' : 'Loss'} + +
+
+ )} +
+ {/* Partnership Performance */}