TO set map pool to tournament query

This commit is contained in:
Kalle 2024-06-10 21:40:07 +03:00
parent f9e45fbdaa
commit f8a5bfb272
7 changed files with 27 additions and 39 deletions

View File

@ -3,10 +3,7 @@ import * as React from "react";
import { Dialog } from "~/components/Dialog";
import { generateTournamentRoundMaplist } from "../core/toMapList";
import type { Bracket } from "../core/Bracket";
import {
useTournament,
useTournamentToSetMapPool,
} from "~/features/tournament/routes/to.$id";
import { useTournament } from "~/features/tournament/routes/to.$id";
import invariant from "~/utils/invariant";
import { type TournamentRoundMaps } from "~/db/tables";
import { useTranslation } from "react-i18next";
@ -35,7 +32,6 @@ export function BracketMapListDialog({
bracket: Bracket;
bracketIdx: number;
}) {
const toSetMapPool = useTournamentToSetMapPool();
const fetcher = useFetcher();
const tournament = useTournament();
@ -50,7 +46,7 @@ export function BracketMapListDialog({
generateTournamentRoundMaplist({
mapCounts: bracket.defaultRoundBestOfs,
roundsWithPickBan,
pool: toSetMapPool,
pool: tournament.ctx.toSetMapPool,
rounds: bracket.data.round,
type: bracket.type,
pickBanStyle,
@ -138,7 +134,8 @@ export function BracketMapListDialog({
};
const lacksToSetMapPool =
toSetMapPool.length === 0 && tournament.ctx.mapPickingStyle === "TO";
tournament.ctx.toSetMapPool.length === 0 &&
tournament.ctx.mapPickingStyle === "TO";
const globalSelections =
bracket.type === "round_robin" || bracket.type === "swiss";
@ -184,7 +181,7 @@ export function BracketMapListDialog({
setMaps(
generateTournamentRoundMaplist({
mapCounts,
pool: toSetMapPool,
pool: tournament.ctx.toSetMapPool,
rounds: bracket.data.round,
type: bracket.type,
roundsWithPickBan: newRoundsWithPickBan,
@ -199,7 +196,7 @@ export function BracketMapListDialog({
const newMapCounts = mapCountsWithGlobalCount(newCount);
const newMaps = generateTournamentRoundMaplist({
mapCounts: newMapCounts,
pool: toSetMapPool,
pool: tournament.ctx.toSetMapPool,
rounds: bracket.data.round,
type: bracket.type,
roundsWithPickBan,
@ -214,7 +211,7 @@ export function BracketMapListDialog({
<GlobalCountTypeSelect onSetCountType={setCountType} />
) : null}
</div>
{toSetMapPool.length > 0 ? (
{tournament.ctx.toSetMapPool.length > 0 ? (
<Button
size="tiny"
icon={<RefreshArrowsIcon />}
@ -223,7 +220,7 @@ export function BracketMapListDialog({
setMaps(
generateTournamentRoundMaplist({
mapCounts,
pool: toSetMapPool,
pool: tournament.ctx.toSetMapPool,
rounds: bracket.data.round,
type: bracket.type,
roundsWithPickBan,
@ -272,7 +269,7 @@ export function BracketMapListDialog({
const newMaps = generateTournamentRoundMaplist({
mapCounts: newMapCounts,
pool: toSetMapPool,
pool: tournament.ctx.toSetMapPool,
rounds: bracket.data.round,
type: bracket.type,
roundsWithPickBan,
@ -297,7 +294,7 @@ export function BracketMapListDialog({
setMaps(
generateTournamentRoundMaplist({
mapCounts,
pool: toSetMapPool,
pool: tournament.ctx.toSetMapPool,
rounds: bracket.data.round,
type: bracket.type,
roundsWithPickBan: newRoundsWithPickBan,
@ -532,7 +529,7 @@ function MapListRow({
hoveredMap: string | null;
}) {
const { t } = useTranslation(["game-misc"]);
const toSetMaps = useTournamentToSetMapPool();
const tournament = useTournament();
if (editing) {
return (
@ -549,7 +546,7 @@ function MapListRow({
});
}}
>
{toSetMaps.map((map) => (
{tournament.ctx.toSetMapPool.map((map) => (
<option
key={serializedMapMode(map)}
value={serializedMapMode(map)}

View File

@ -9,10 +9,7 @@ import { SubmitButton } from "~/components/SubmitButton";
import { CheckmarkIcon } from "~/components/icons/Checkmark";
import { CrossIcon } from "~/components/icons/Cross";
import { useUser } from "~/features/auth/core/user";
import {
useTournament,
useTournamentToSetMapPool,
} from "~/features/tournament/routes/to.$id";
import { useTournament } from "~/features/tournament/routes/to.$id";
import {
type ModeShort,
type StageId,
@ -74,11 +71,10 @@ function MapPicker({
}) {
const user = useUser();
const data = useLoaderData<TournamentMatchLoaderData>();
const toSetMapPool = useTournamentToSetMapPool();
const tournament = useTournament();
const pickBanMapPool = PickBan.mapsListWithLegality({
toSetMapPool,
toSetMapPool: tournament.ctx.toSetMapPool,
maps: data.match.roundMaps,
mapList: data.mapList,
teams,

View File

@ -6245,6 +6245,7 @@ export const PADDLING_POOL_257 = () =>
bestOf: 5,
},
],
toSetMapPool: [],
tieBreakerMapPool: [
{
stageId: 15,
@ -11977,6 +11978,7 @@ export const PADDLING_POOL_255 = () =>
bestOf: 5,
},
],
toSetMapPool: [],
tieBreakerMapPool: [
{
stageId: 15,
@ -17355,6 +17357,7 @@ export const IN_THE_ZONE_32 = () =>
bestOf: 5,
},
],
toSetMapPool: [],
tieBreakerMapPool: [],
participatedUsers: [
8, 18, 32, 35, 36, 41, 48, 50, 57, 70, 76, 81, 94, 100, 104, 112, 115,

View File

@ -62,6 +62,7 @@ export const testTournament = (
subCounts: [],
staff: [],
tieBreakerMapPool: [],
toSetMapPool: [],
participatedUsers: [],
mapPickingStyle: "AUTO_SZ",
settings: {

View File

@ -163,6 +163,12 @@ export async function findById(id: number) {
"CalendarEvent.id",
),
).as("tieBreakerMapPool"),
jsonArrayFrom(
eb
.selectFrom("MapPoolMap")
.select(["MapPoolMap.mode", "MapPoolMap.stageId"])
.whereRef("MapPoolMap.calendarEventId", "=", "CalendarEvent.id"),
).as("toSetMapPool"),
jsonArrayFrom(
eb
.selectFrom("TournamentStage")

View File

@ -69,11 +69,7 @@ import {
isOneModeTournamentOf,
tournamentIdFromParams,
} from "../tournament-utils";
import {
useTournament,
useTournamentFriendCode,
useTournamentToSetMapPool,
} from "./to.$id";
import { useTournament, useTournamentFriendCode } from "./to.$id";
import Markdown from "markdown-to-jsx";
import { NewTabs } from "~/components/NewTabs";
import { useSearchParamState } from "~/hooks/useSearchParamState";
@ -1345,15 +1341,14 @@ function validateCounterPickMapPool(
function TOPickedMapPoolInfo() {
const { t } = useTranslation(["calendar"]);
const toSetMapPool = useTournamentToSetMapPool();
const tournament = useTournament();
if (toSetMapPool.length === 0) return null;
if (tournament.ctx.toSetMapPool.length === 0) return null;
return (
<Section title={t("calendar:forms.mapPool")}>
<div className="event__map-pool-section">
<MapPoolStages mapPool={new MapPool(toSetMapPool)} />
<MapPoolStages mapPool={new MapPool(tournament.ctx.toSetMapPool)} />
<LinkButton
className="event__create-map-list-link"
to={readonlyMapsPage(tournament.ctx.eventId)}

View File

@ -138,10 +138,6 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
tournament,
streamingParticipants: streams.flatMap((s) => (s.userId ? [s.userId] : [])),
streamsCount: streams.length,
toSetMapPool:
tournament.ctx.mapPickingStyle === "TO"
? await TournamentRepository.findTOSetMapPoolById(tournamentId)
: [],
friendCode: user
? await UserRepository.currentFriendCodeByUserId(user.id)
: undefined,
@ -240,7 +236,6 @@ export default function TournamentLayout() {
streamingParticipants: data.streamingParticipants,
friendCode: data.friendCode?.friendCode,
friendCodes: data.friendCodes,
toSetMapPool: data.toSetMapPool,
} satisfies TournamentContext
}
/>
@ -256,7 +251,6 @@ type TournamentContext = {
setBracketExpanded: (expanded: boolean) => void;
friendCode?: string;
friendCodes?: SerializeFrom<typeof loader>["friendCodes"];
toSetMapPool: SerializeFrom<typeof loader>["toSetMapPool"];
};
export function useTournament() {
@ -281,7 +275,3 @@ export function useTournamentFriendCode() {
export function useTournamentFriendCodes() {
return useOutletContext<TournamentContext>().friendCodes;
}
export function useTournamentToSetMapPool() {
return useOutletContext<TournamentContext>().toSetMapPool;
}