match h2h

This commit is contained in:
yohlo
2025-10-11 13:40:12 -05:00
parent 14c2eb2c02
commit 43972b6a06
6 changed files with 383 additions and 23 deletions

View File

@@ -0,0 +1,24 @@
import { useServerQuery } from "@/lib/tanstack-query/hooks";
import { getMatchesBetweenTeams, getMatchesBetweenPlayers } from "./server";
export const matchKeys = {
headToHeadTeams: (team1Id: string, team2Id: string) => ['matches', 'headToHead', 'teams', team1Id, team2Id] as const,
headToHeadPlayers: (player1Id: string, player2Id: string) => ['matches', 'headToHead', 'players', player1Id, player2Id] as const,
};
export const matchQueries = {
headToHeadTeams: (team1Id: string, team2Id: string) => ({
queryKey: matchKeys.headToHeadTeams(team1Id, team2Id),
queryFn: () => getMatchesBetweenTeams({ data: { team1Id, team2Id } }),
}),
headToHeadPlayers: (player1Id: string, player2Id: string) => ({
queryKey: matchKeys.headToHeadPlayers(player1Id, player2Id),
queryFn: () => getMatchesBetweenPlayers({ data: { player1Id, player2Id } }),
}),
};
export const useTeamHeadToHead = (team1Id: string, team2Id: string) =>
useServerQuery(matchQueries.headToHeadTeams(team1Id, team2Id));
export const usePlayerHeadToHead = (player1Id: string, player2Id: string) =>
useServerQuery(matchQueries.headToHeadPlayers(player1Id, player2Id));