fix stats breaking new player profiles
This commit is contained in:
@@ -101,10 +101,10 @@ const StatsOverview = ({ statsData, isLoading = false }: StatsOverviewProps) =>
|
|||||||
{ label: "Losses", value: overallStats.losses, Icon: XIcon },
|
{ label: "Losses", value: overallStats.losses, Icon: XIcon },
|
||||||
{ label: "Cups Made", value: overallStats.total_cups_made, Icon: FireIcon },
|
{ label: "Cups Made", value: overallStats.total_cups_made, Icon: FireIcon },
|
||||||
{ label: "Cups Against", value: overallStats.total_cups_against, Icon: ShieldIcon },
|
{ label: "Cups Against", value: overallStats.total_cups_against, Icon: ShieldIcon },
|
||||||
{ label: "Avg Cups Per Game", value: avgCupsPerMatch > 0 ? avgCupsPerMatch : null, Icon: ChartLineUpIcon },
|
{ label: "Avg Cups Per Game", value: avgCupsPerMatch >= 0 ? avgCupsPerMatch : null, Icon: ChartLineUpIcon },
|
||||||
{ label: "Avg Cups Against", value: avgCupsAgainstPerMatch > 0 ? avgCupsAgainstPerMatch : null, Icon: ShieldCheckIcon },
|
{ label: "Avg Cups Against", value: avgCupsAgainstPerMatch >= 0 ? avgCupsAgainstPerMatch : null, Icon: ShieldCheckIcon },
|
||||||
{ label: "Avg Win Margin", value: avgMarginOfVictory > 0 ? avgMarginOfVictory : null, Icon: ArrowUpIcon },
|
{ label: "Avg Win Margin", value: avgMarginOfVictory >= 0 ? avgMarginOfVictory : null, Icon: ArrowUpIcon },
|
||||||
{ label: "Avg Loss Margin", value: avgMarginOfLoss > 0 ? avgMarginOfLoss : null, Icon: ArrowDownIcon },
|
{ label: "Avg Loss Margin", value: avgMarginOfLoss >= 0 ? avgMarginOfLoss : null, Icon: ArrowDownIcon },
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -66,10 +66,28 @@ export function createPlayersService(pb: PocketBase) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async getPlayerStats(playerId: string): Promise<PlayerStats> {
|
async getPlayerStats(playerId: string): Promise<PlayerStats> {
|
||||||
const result = await pb.collection("player_stats").getFirstListItem<PlayerStats>(
|
try {
|
||||||
`player_id = "${playerId}"`
|
const result = await pb.collection("player_stats").getFirstListItem<PlayerStats>(
|
||||||
);
|
`player_id = "${playerId}"`
|
||||||
return result;
|
);
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
id: "",
|
||||||
|
player_id: playerId,
|
||||||
|
player_name: "",
|
||||||
|
matches: 0,
|
||||||
|
tournaments: 0,
|
||||||
|
wins: 0,
|
||||||
|
losses: 0,
|
||||||
|
total_cups_made: 0,
|
||||||
|
total_cups_against: 0,
|
||||||
|
win_percentage: 0,
|
||||||
|
avg_cups_per_match: 0,
|
||||||
|
margin_of_victory: 0,
|
||||||
|
margin_of_loss: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async getAllPlayerStats(): Promise<PlayerStats[]> {
|
async getAllPlayerStats(): Promise<PlayerStats[]> {
|
||||||
|
|||||||
Reference in New Issue
Block a user