feat: add tournaments participated and recent matches to player profile
This commit is contained in:
@@ -35,6 +35,40 @@ export default async function PlayerProfilePage({ params }: PageProps) {
|
|||||||
orderBy: { gamesPlayed: "desc" },
|
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)
|
// Use direct player stats for overall statistics (more accurate and consistent with rankings page)
|
||||||
const totalGames = player.gamesPlayed
|
const totalGames = player.gamesPlayed
|
||||||
const totalWins = player.wins
|
const totalWins = player.wins
|
||||||
@@ -95,6 +129,171 @@ export default async function PlayerProfilePage({ params }: PageProps) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Tournaments Participated */}
|
||||||
|
<div className="bg-white shadow rounded-lg p-6 mb-6">
|
||||||
|
<h2 className="text-xl font-bold text-gray-900 mb-4">
|
||||||
|
Tournaments Participated
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
{tournaments.length === 0 ? (
|
||||||
|
<p className="text-gray-500">No tournament data available yet.</p>
|
||||||
|
) : (
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="min-w-full divide-y divide-gray-200">
|
||||||
|
<thead className="bg-gray-50">
|
||||||
|
<tr>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Tournament
|
||||||
|
</th>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Date
|
||||||
|
</th>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Format
|
||||||
|
</th>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Status
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="bg-white divide-y divide-gray-200">
|
||||||
|
{tournaments.map((tournament) => (
|
||||||
|
<tr key={tournament.id} className="hover:bg-gray-50">
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap">
|
||||||
|
<Link
|
||||||
|
href={`/players/${playerId}/schedule?tournament=${tournament.id}`}
|
||||||
|
className="text-green-600 hover:text-green-900"
|
||||||
|
>
|
||||||
|
{tournament.name}
|
||||||
|
</Link>
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||||
|
{tournament.eventDate
|
||||||
|
? new Date(tournament.eventDate).toLocaleDateString()
|
||||||
|
: "N/A"}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||||
|
{tournament.format}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap">
|
||||||
|
<span className={`inline-flex px-2 py-1 text-xs font-semibold leading-5 rounded-full ${
|
||||||
|
tournament.status === 'active' || tournament.status === 'in_progress'
|
||||||
|
? 'bg-green-100 text-green-800'
|
||||||
|
: tournament.status === 'completed'
|
||||||
|
? 'bg-gray-100 text-gray-800'
|
||||||
|
: 'bg-yellow-100 text-yellow-800'
|
||||||
|
}`}>
|
||||||
|
{tournament.status}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Recent Games */}
|
||||||
|
<div className="bg-white shadow rounded-lg p-6 mb-6">
|
||||||
|
<h2 className="text-xl font-bold text-gray-900 mb-4">
|
||||||
|
Recent Games
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
{recentMatches.length === 0 ? (
|
||||||
|
<p className="text-gray-500">No game data available yet.</p>
|
||||||
|
) : (
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="min-w-full divide-y divide-gray-200">
|
||||||
|
<thead className="bg-gray-50">
|
||||||
|
<tr>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Date
|
||||||
|
</th>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Tournament
|
||||||
|
</th>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Team
|
||||||
|
</th>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Opponents
|
||||||
|
</th>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Score
|
||||||
|
</th>
|
||||||
|
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Result
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="bg-white divide-y divide-gray-200">
|
||||||
|
{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 (
|
||||||
|
<tr key={match.id} className="hover:bg-gray-50">
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||||
|
{match.playedAt
|
||||||
|
? new Date(match.playedAt).toLocaleDateString()
|
||||||
|
: "N/A"}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||||
|
{match.event?.name || "N/A"}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||||
|
<Link
|
||||||
|
href={`/players/${teammate.id}/profile`}
|
||||||
|
className="text-green-600 hover:text-green-900"
|
||||||
|
>
|
||||||
|
{teammate.name}
|
||||||
|
</Link>
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||||
|
{opponents.map((opponent, index) => (
|
||||||
|
<span key={opponent.id}>
|
||||||
|
<Link
|
||||||
|
href={`/players/${opponent.id}/profile`}
|
||||||
|
className="text-green-600 hover:text-green-900"
|
||||||
|
>
|
||||||
|
{opponent.name}
|
||||||
|
</Link>
|
||||||
|
{index < opponents.length - 1 ? ", " : ""}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
||||||
|
{teamScore} - {opponentScore}
|
||||||
|
</td>
|
||||||
|
<td className="px-6 py-4 whitespace-nowrap">
|
||||||
|
<span className={`inline-flex px-2 py-1 text-xs font-semibold leading-5 rounded-full ${
|
||||||
|
teamWon
|
||||||
|
? 'bg-green-100 text-green-800'
|
||||||
|
: 'bg-red-100 text-red-800'
|
||||||
|
}`}>
|
||||||
|
{teamWon ? 'Win' : 'Loss'}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
{/* Partnership Performance */}
|
{/* Partnership Performance */}
|
||||||
<div className="bg-white shadow rounded-lg p-6">
|
<div className="bg-white shadow rounded-lg p-6">
|
||||||
<h2 className="text-xl font-bold text-gray-900 mb-4">
|
<h2 className="text-xl font-bold text-gray-900 mb-4">
|
||||||
|
|||||||
Reference in New Issue
Block a user