match status

This commit is contained in:
yohlo
2025-09-11 14:04:05 -05:00
parent 22be6682dd
commit 8dfff139e1
8 changed files with 89 additions and 20 deletions

View File

@@ -35,8 +35,8 @@ export const MatchCard: React.FC<MatchCardProps> = ({
);
const showToolbar = useMemo(
() => match.home && match.away && onStartMatch,
[match.home, match.away]
() => match.status === "ready" && onStartMatch,
[match.status, onStartMatch]
);
const handleAnnounce = useCallback(

View File

@@ -58,6 +58,7 @@ export const generateTournamentBracket = createServerFn()
home_from_loser: match.home_from_loser || false,
away_from_loser: match.away_from_loser || false,
is_losers_bracket: false,
status: "tbd",
tournament: tournamentId,
};
@@ -77,6 +78,10 @@ export const generateTournamentBracket = createServerFn()
}
}
if (matchInput.home && matchInput.away) {
matchInput.status = "ready"
}
matchInputs.push(matchInput);
});
});
@@ -97,6 +102,7 @@ export const generateTournamentBracket = createServerFn()
home_from_loser: match.home_from_loser || false,
away_from_loser: match.away_from_loser || false,
is_losers_bracket: true,
status: "tbd",
tournament: tournamentId,
};
@@ -135,7 +141,38 @@ export const startMatch = createServerFn()
}
match = await pbAdmin.updateMatch(data, {
start_time: new Date().toISOString()
start_time: new Date().toISOString(),
status: "started"
});
return match;
}
));
const endMatchSchema = z.object({
matchId: z.string(),
home_cups: z.number(),
away_cups: z.number(),
ot_count: z.number()
});
export const endMatch = createServerFn()
.validator(endMatchSchema)
.middleware([superTokensAdminFunctionMiddleware])
.handler(async ({ data: { matchId, home_cups, away_cups, ot_count } }) =>
toServerResult(async () => {
logger.info('Ending match', matchId);
let match = await pbAdmin.getMatch(matchId);
if (!match) {
throw new Error('Match not found');
}
match = await pbAdmin.updateMatch(matchId, {
end_time: new Date().toISOString(),
status: "ended",
home_cups,
away_cups,
ot_count
})
}
));

View File

@@ -2,6 +2,8 @@ import { z } from "zod";
import { TeamInfo } from "../teams/types";
import { TournamentInfo } from "../tournaments/types";
export type MatchStatus = "tbd" | "ready" | "started" | "ended";
/**
* class TMatchSlot(BaseModel):
pass
@@ -52,6 +54,7 @@ export interface Match {
home_from_loser: boolean;
away_from_loser: boolean;
is_losers_bracket: boolean;
status: MatchStatus;
tournament: TournamentInfo;
home?: TeamInfo;
away?: TeamInfo;
@@ -77,6 +80,7 @@ export const matchInputSchema = z.object({
home_from_loser: z.boolean().optional().default(false),
away_from_loser: z.boolean().optional().default(false),
is_losers_bracket: z.boolean().optional().default(false),
status: z.enum(["tbd", "ready", "started", "ended"]).optional().default("tbd"),
tournament: z.string().min(1),
home: z.string().min(1).optional(),
away: z.string().min(1).optional(),

View File

@@ -17,20 +17,21 @@ import Avatar from "@/components/avatar";
import { useBracketPreview } from "@/features/bracket/queries";
import { BracketData } from "@/features/bracket/types";
import BracketView from "@/features/bracket/components/bracket-view";
import { useQueryClient } from "@tanstack/react-query";
import { tournamentKeys } from "../queries";
interface SeedTournamentProps {
tournamentId: string;
teams: TeamInfo[];
onSuccess?: () => void;
}
const SeedTournament: React.FC<SeedTournamentProps> = ({
tournamentId,
teams,
onSuccess,
teams
}) => {
const [orderedTeams, setOrderedTeams] = useState<TeamInfo[]>(teams);
const { data: bracketPreview } = useBracketPreview(teams.length);
const queryClient = useQueryClient()
const bracket: BracketData = useMemo(
() => ({
@@ -56,7 +57,9 @@ const SeedTournament: React.FC<SeedTournamentProps> = ({
mutationFn: generateTournamentBracket,
successMessage: "Tournament bracket generated successfully!",
onSuccess: () => {
onSuccess?.();
queryClient.invalidateQueries({
queryKey: tournamentKeys.details(tournamentId)
})
},
});