diff --git a/brackets/11.json b/brackets/11.json new file mode 100644 index 0000000..9feabaf --- /dev/null +++ b/brackets/11.json @@ -0,0 +1,323 @@ +{ + "winners": [ + [ + { + "lid": 0, + "round": 0, + "order": null, + "bye": true, + "home_from_lid": null, + "home_from_loser": null, + "home_seed": 1 + }, + { + "lid": 1, + "round": 0, + "order": 1, + "bye": false, + "home_from_lid": null, + "home_from_loser": null, + "home_seed": 8, + "away_seed": 9, + "away_from_lid": null, + "away_from_loser": null, + "reset": false + }, + { + "lid": 2, + "round": 0, + "order": null, + "bye": true, + "home_from_lid": null, + "home_from_loser": null, + "home_seed": 4 + }, + { + "lid": 3, + "round": 0, + "order": null, + "bye": true, + "home_from_lid": null, + "home_from_loser": null, + "home_seed": 5 + }, + { + "lid": 4, + "round": 0, + "order": null, + "bye": true, + "home_from_lid": null, + "home_from_loser": null, + "home_seed": 2 + }, + { + "lid": 5, + "round": 0, + "order": 2, + "bye": false, + "home_from_lid": null, + "home_from_loser": null, + "home_seed": 7, + "away_seed": 10, + "away_from_lid": null, + "away_from_loser": null, + "reset": false + }, + { + "lid": 6, + "round": 0, + "order": null, + "bye": true, + "home_from_lid": null, + "home_from_loser": null, + "home_seed": 3 + }, + { + "lid": 7, + "round": 0, + "order": 3, + "bye": false, + "home_from_lid": null, + "home_from_loser": null, + "home_seed": 6, + "away_seed": 11, + "away_from_lid": null, + "away_from_loser": null, + "reset": false + } + ], + [ + { + "lid": 8, + "round": 1, + "order": 5, + "bye": false, + "home_from_lid": null, + "home_from_loser": null, + "home_seed": 1, + "away_from_lid": 1, + "away_from_loser": false, + "reset": false + }, + { + "lid": 9, + "round": 1, + "order": 4, + "bye": false, + "home_from_lid": null, + "home_from_loser": null, + "home_seed": 4, + "away_seed": 5, + "away_from_lid": null, + "away_from_loser": null, + "reset": false + }, + { + "lid": 10, + "round": 1, + "order": 6, + "bye": false, + "home_from_lid": null, + "home_from_loser": null, + "home_seed": 2, + "away_from_lid": 5, + "away_from_loser": false, + "reset": false + }, + { + "lid": 11, + "round": 1, + "order": 7, + "bye": false, + "home_from_lid": null, + "home_from_loser": null, + "home_seed": 3, + "away_from_lid": 7, + "away_from_loser": null, + "reset": false + } + ], + [ + { + "lid": 18, + "round": 2, + "order": 13, + "bye": false, + "home_from_lid": 8, + "home_from_loser": false, + "away_from_lid": 9, + "away_from_loser": false, + "reset": false + }, + { + "lid": 19, + "round": 2, + "order": 14, + "bye": false, + "home_from_lid": 10, + "home_from_loser": false, + "away_from_lid": 11, + "away_from_loser": false, + "reset": false + } + ], + [ + { + "lid": 23, + "round": 3, + "order": 16, + "bye": false, + "home_from_lid": 18, + "home_from_loser": false, + "away_from_lid": 19, + "away_from_loser": false, + "reset": false + } + ], + [ + { + "lid": 25, + "round": 4, + "order": 18, + "bye": false, + "home_from_lid": 23, + "home_from_loser": false, + "away_from_lid": 24, + "away_from_loser": false, + "reset": false + } + ], + [ + { + "lid": 26, + "round": 5, + "order": 19, + "bye": false, + "home_from_lid": 25, + "home_from_loser": false, + "away_from_lid": 25, + "away_from_loser": true, + "reset": true + } + ] + ], + "losers": [ + [ + { + "lid": 12, + "round": 0, + "order": null, + "bye": true, + "home_from_lid": 10, + "home_from_loser": true + }, + { + "lid": 13, + "round": 0, + "order": 10, + "bye": false, + "home_from_lid": 11, + "home_from_loser": true, + "away_from_lid": 1, + "away_from_loser": true, + "reset": false + }, + { + "lid": 14, + "round": 0, + "order": 8, + "bye": false, + "home_from_lid": 9, + "home_from_loser": true, + "away_from_lid": 5, + "away_from_loser": true, + "reset": false + }, + { + "lid": 15, + "round": 0, + "order": 9, + "bye": false, + "home_from_lid": 8, + "home_from_loser": true, + "away_from_lid": 7, + "away_from_loser": true, + "reset": false + } + ], + [ + { + "lid": 16, + "round": 1, + "order": 9, + "bye": false, + "home_from_lid": 10, + "home_from_loser": true, + "away_from_lid": 13, + "away_from_loser": false, + "reset": false + }, + { + "lid": 17, + "round": 1, + "order": 10, + "bye": false, + "home_from_lid": 14, + "home_from_loser": false, + "away_from_lid": 15, + "away_from_loser": false, + "reset": false + } + ], + [ + { + "lid": 20, + "round": 2, + "order": 13, + "bye": false, + "home_from_lid": 18, + "home_from_loser": true, + "away_from_lid": 16, + "away_from_loser": false, + "reset": false + }, + { + "lid": 21, + "round": 2, + "order": 14, + "bye": false, + "home_from_lid": 19, + "home_from_loser": true, + "away_from_lid": 17, + "away_from_loser": false, + "reset": false + } + ], + [ + { + "lid": 22, + "round": 3, + "order": 15, + "bye": false, + "home_from_lid": 20, + "home_from_loser": false, + "away_from_lid": 21, + "away_from_loser": false, + "reset": false + } + ], + [ + { + "lid": 24, + "round": 4, + "order": 17, + "bye": false, + "home_from_lid": 23, + "home_from_loser": true, + "away_from_lid": 22, + "away_from_loser": false, + "reset": false + } + ] + ] +} \ No newline at end of file diff --git a/src/features/bracket/components/match-form.tsx b/src/features/bracket/components/match-form.tsx index bc8b839..278734c 100644 --- a/src/features/bracket/components/match-form.tsx +++ b/src/features/bracket/components/match-form.tsx @@ -1,4 +1,4 @@ -import { Button, TextInput, Stack, Group, Text, Flex, Divider } from "@mantine/core"; +import { Button, TextInput, Stack, Group, Text, Flex, Divider, NumberInput } from "@mantine/core"; import { useForm } from "@mantine/form"; import { Match } from "@/features/matches/types"; @@ -92,11 +92,10 @@ export const MatchForm: React.FC = ({ )) } - = ({ )) } - where to send match winner to, loser same const { winner, loser } = await pbAdmin.getChildMatches(matchId); @@ -207,7 +210,7 @@ export const endMatch = createServerFn() // advance bracket if (winner) { await pbAdmin.updateMatch(winner.id, { - [winner.home_from_lid === match.lid ? "home" : "away"]: matchWinner, + [winner.home_from_lid === match.lid ? "home" : "away"]: matchWinner.id, status: (winner.home_from_lid === match.lid && winner.away) || (winner.away_from_lid === match.lid && winner.home) @@ -218,7 +221,7 @@ export const endMatch = createServerFn() if (loser) { await pbAdmin.updateMatch(loser.id, { - [loser.home_from_lid === match.lid ? "home" : "away"]: matchLoser, + [loser.home_from_lid === match.lid ? "home" : "away"]: matchLoser.id, status: (loser.home_from_lid === match.lid && loser.away) || (loser.away_from_lid === match.lid && loser.home) diff --git a/src/lib/pocketbase/services/matches.ts b/src/lib/pocketbase/services/matches.ts index b376146..de7dc04 100644 --- a/src/lib/pocketbase/services/matches.ts +++ b/src/lib/pocketbase/services/matches.ts @@ -20,7 +20,7 @@ export function createMatchesService(pb: PocketBase) { if (!match) throw new Error("Match not found") const result = await pb.collection("matches").getFullList({ - filter: `tournament="${match.tournament.id}" && (home_from_lid = ${match.lid} || away_from_lid = ${match.lid})`, + filter: `tournament="${match.tournament.id}" && (home_from_lid = ${match.lid} || away_from_lid = ${match.lid}) && bye = false`, expand: "tournament, home, away", }); @@ -51,8 +51,10 @@ export function createMatchesService(pb: PocketBase) { async updateMatch(id: string, data: Partial): Promise { logger.info("PocketBase | Updating match", { id, data }); - const result = await pb.collection("matches").update(id, data); - return result; + const result = await pb.collection("matches").update(id, data, { + expand: 'home, away' + }); + return transformMatch(result); }, async deleteMatch(id: string): Promise { diff --git a/src/lib/pocketbase/util/transform-types.ts b/src/lib/pocketbase/util/transform-types.ts index 2f0e5e3..58abe2e 100644 --- a/src/lib/pocketbase/util/transform-types.ts +++ b/src/lib/pocketbase/util/transform-types.ts @@ -44,9 +44,9 @@ export const transformMatch = (record: any): Match => { away_from_loser: record.away_from_loser, is_losers_bracket: record.is_losers_bracket, status: record.status || "tbd", - tournament: transformTournamentInfo(record.expand?.tournament), - home: record.expand?.home ? transformTeamInfo(record.expand.home) : undefined, - away: record.expand?.away ? transformTeamInfo(record.expand.away) : undefined, + tournament: record.expand?.tournament ? transformTournamentInfo(record.expand?.tournament) : record.tournament, + home: record.expand?.home ? transformTeamInfo(record.expand.home) : record.home, + away: record.expand?.away ? transformTeamInfo(record.expand.away) : record.away, created: record.created, updated: record.updated, home_seed: record.home_seed,