feat(ui): update home page with top players, recent tournament, and club president
This commit is contained in:
@@ -14,39 +14,39 @@ export default async function PlayerProfilePage({ params }: PageProps) {
|
||||
|
||||
const player = await prisma.player.findUnique({
|
||||
where: { id: playerId },
|
||||
include: {
|
||||
partnershipStats: {
|
||||
include: {
|
||||
player1: true,
|
||||
player2: true,
|
||||
},
|
||||
orderBy: { gamesPlayed: "desc" },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if (!player) {
|
||||
notFound()
|
||||
}
|
||||
|
||||
// Calculate overall statistics
|
||||
const totalGames = player.partnershipStats.reduce(
|
||||
(sum, stat) => sum + stat.gamesPlayed,
|
||||
0
|
||||
)
|
||||
const totalWins = player.partnershipStats.reduce(
|
||||
(sum, stat) => sum + stat.wins,
|
||||
0
|
||||
)
|
||||
// Get partnership stats separately
|
||||
const partnershipStats = await prisma.partnershipStat.findMany({
|
||||
where: {
|
||||
OR: [
|
||||
{ player1Id: playerId },
|
||||
{ player2Id: playerId },
|
||||
],
|
||||
},
|
||||
include: {
|
||||
player1: true,
|
||||
player2: true,
|
||||
},
|
||||
orderBy: { gamesPlayed: "desc" },
|
||||
})
|
||||
|
||||
// Use direct player stats for overall statistics (more accurate and consistent with rankings page)
|
||||
const totalGames = player.gamesPlayed
|
||||
const totalWins = player.wins
|
||||
const winRate = totalGames > 0 ? ((totalWins / totalGames) * 100).toFixed(1) : "0.0"
|
||||
|
||||
// Get best partnership
|
||||
const bestPartnership = player.partnershipStats.reduce((best, stat) => {
|
||||
const bestPartnership = partnershipStats.reduce((best, stat) => {
|
||||
if (stat.gamesPlayed < 3) return best // Need at least 3 games for partnership to be meaningful
|
||||
const currentRate = stat.wins / stat.gamesPlayed
|
||||
const bestRate = best ? best.wins / best.gamesPlayed : 0
|
||||
return currentRate > bestRate ? stat : best
|
||||
}, null as typeof player.partnershipStats[0] | null)
|
||||
}, null as (typeof partnershipStats[0] | null))
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
@@ -101,7 +101,7 @@ export default async function PlayerProfilePage({ params }: PageProps) {
|
||||
Partnership Performance
|
||||
</h2>
|
||||
|
||||
{player.partnershipStats.length === 0 ? (
|
||||
{partnershipStats.length === 0 ? (
|
||||
<p className="text-gray-500">No partnership data available yet.</p>
|
||||
) : (
|
||||
<div className="overflow-x-auto">
|
||||
@@ -126,7 +126,7 @@ export default async function PlayerProfilePage({ params }: PageProps) {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="bg-white divide-y divide-gray-200">
|
||||
{player.partnershipStats.map((stat) => {
|
||||
{partnershipStats.map((stat) => {
|
||||
const partner =
|
||||
stat.player1Id === player.id ? stat.player2 : stat.player1
|
||||
const winRate = stat.gamesPlayed > 0
|
||||
|
||||
Reference in New Issue
Block a user