diff --git a/src/app/page.tsx b/src/app/page.tsx index b85aaf4..9cd627f 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,6 +1,233 @@ -import { redirect } from "next/navigation" +import { prisma } from "@/lib/prisma" +import Link from "next/link" -export default function Home() { - // Redirect to rankings as the main entry point - redirect("/rankings") +export default async function Home() { + // Fetch top 10 players by Elo rating + const topPlayers = await prisma.player.findMany({ + orderBy: { currentElo: "desc" }, + take: 10, + include: { + partnershipStats: true, + partnershipStats2: true, + }, + }) + + // Fetch most recent tournament + const mostRecentTournament = await prisma.event.findFirst({ + where: { + eventType: "tournament", + status: { not: "draft" } + }, + orderBy: { eventDate: "desc" }, + include: { + matches: { + include: { + team1P1: true, + team1P2: true, + team2P1: true, + team2P2: true, + }, + orderBy: { playedAt: "desc" }, + }, + }, + }) + + // Fetch club president (first user with club_admin role) + const clubPresident = await prisma.user.findFirst({ + where: { role: "club_admin" }, + select: { name: true, email: true }, + }) + + // Calculate win rates for top players + const playersWithWinRates = topPlayers.map((player) => ({ + ...player, + winRate: player.gamesPlayed > 0 + ? (player.wins / player.gamesPlayed) * 100 + : 0, + })) + + return ( +
+
+ {/* Header Section */} +
+

+ EuchreCamp +

+

+ Track your Euchre games, tournaments, and partnership performance + with our comprehensive tournament management system. +

+ +
+ + Sign In + + + Create Account + +
+
+ + {/* Top 10 Players Section */} +
+

+ Top 10 Players +

+
+ + + + + + + + + + + + {playersWithWinRates.map((player, index) => ( + + + + + + + + ))} + +
+ Rank + + Player + + Elo Rating + + Games + + Win Rate +
+ {index + 1} + + + {player.name} + + + {player.currentElo} + + {player.gamesPlayed} + + {player.gamesPlayed > 0 + ? `${player.winRate.toFixed(1)}%` + : "N/A"} +
+
+
+ + View Full Rankings → + +
+
+ + {/* Most Recent Tournament Section */} + {mostRecentTournament && ( +
+

+ Most Recent Tournament +

+
+

+ {mostRecentTournament.name} +

+ {mostRecentTournament.eventDate && ( +

+ {new Date(mostRecentTournament.eventDate).toLocaleDateString()} +

+ )} +

+ Status: {mostRecentTournament.status} +

+
+ + {/* Tournament Matches */} +
+

+ Matches ({mostRecentTournament.matches.length}) +

+
+ {mostRecentTournament.matches.map((match) => ( +
+
+
+
+ {match.team1P1.name} & {match.team1P2.name} +
+
+ {match.team1Score} +
+
+
vs
+
+
+ {match.team2P1.name} & {match.team2P2.name} +
+
+ {match.team2Score} +
+
+
+
+ {match.playedAt && ( + + {new Date(match.playedAt).toLocaleDateString()} at{' '} + {new Date(match.playedAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })} + + )} +
+
+ ))} +
+
+
+ )} + + {/* Club President Section */} +
+

+ Club Information +

+
+
+
+ + + +
+
+
+

Club President

+

+ {clubPresident?.name || clubPresident?.email || "Not assigned"} +

+
+
+
+
+
+ ) } diff --git a/src/app/players/[id]/profile/page.tsx b/src/app/players/[id]/profile/page.tsx index 731a45c..c4067a8 100644 --- a/src/app/players/[id]/profile/page.tsx +++ b/src/app/players/[id]/profile/page.tsx @@ -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 (
@@ -101,7 +101,7 @@ export default async function PlayerProfilePage({ params }: PageProps) { Partnership Performance - {player.partnershipStats.length === 0 ? ( + {partnershipStats.length === 0 ? (

No partnership data available yet.

) : (
@@ -126,7 +126,7 @@ export default async function PlayerProfilePage({ params }: PageProps) { - {player.partnershipStats.map((stat) => { + {partnershipStats.map((stat) => { const partner = stat.player1Id === player.id ? stat.player2 : stat.player1 const winRate = stat.gamesPlayed > 0