work on team enrollment

This commit is contained in:
yohlo
2025-09-16 09:24:21 -05:00
parent 9a105b30c6
commit cde74a04d5
45 changed files with 1244 additions and 457 deletions

View File

@@ -1,12 +1,10 @@
import { Box } from "@mantine/core";
import Header from "./header";
import { Player, PlayerStats } from "@/features/players/types";
import SwipeableTabs from "@/components/swipeable-tabs";
import { usePlayer, usePlayerMatches, usePlayerStats } from "../../queries";
import TeamList from "@/features/teams/components/team-list";
import StatsOverview from "@/shared/components/stats-overview";
import MatchList from "@/features/matches/components/match-list";
import { BaseStats } from "@/shared/types/stats";
interface ProfileProps {
id: string;
@@ -17,26 +15,14 @@ const Profile = ({ id }: ProfileProps) => {
const { data: matches } = usePlayerMatches(id);
const { data: stats, isLoading: statsLoading } = usePlayerStats(id);
// Aggregate player stats from multiple tournaments into a single BaseStats object
const aggregatedStats: BaseStats | null = stats && stats.length > 0 ? {
id: `player_${id}_aggregate`,
matches: stats.reduce((acc, stat) => acc + stat.matches, 0),
wins: stats.reduce((acc, stat) => acc + stat.wins, 0),
losses: stats.reduce((acc, stat) => acc + stat.losses, 0),
total_cups_made: stats.reduce((acc, stat) => acc + stat.total_cups_made, 0),
total_cups_against: stats.reduce((acc, stat) => acc + stat.total_cups_against, 0),
margin_of_victory: stats.filter(s => s.margin_of_victory > 0).reduce((acc, stat, _, arr) => acc + stat.margin_of_victory / arr.length, 0),
margin_of_loss: stats.filter(s => s.margin_of_loss > 0).reduce((acc, stat, _, arr) => acc + stat.margin_of_loss / arr.length, 0),
} : null;
const tabs = [
{
label: "Overview",
content: <StatsOverview statsData={aggregatedStats} isLoading={statsLoading} />,
content: <StatsOverview statsData={stats} isLoading={statsLoading} />,
},
{
label: "Matches",
content: <Box p="md"><MatchList matches={matches || []} /></Box>,
content: <MatchList matches={matches || []} />,
},
{
label: "Teams",
@@ -47,7 +33,7 @@ const Profile = ({ id }: ProfileProps) => {
return (
<>
<Header player={player} />
<Box m='md' mt="lg">
<Box m='xs' mt="lg">
<SwipeableTabs tabs={tabs} />
</Box>
</>