sendou.ink/app/features/tournament-bracket/components/ScoreReporterRosters.tsx
Kalle ef78d3a2c2
Tournament full (#1373)
* Got something going

* Style overwrites

* width != height

* More playing with lines

* Migrations

* Start bracket initial

* Unhardcode stage generation params

* Link to match page

* Matches page initial

* Support directly adding seed to map list generator

* Add docs

* Maps in matches page

* Add invariant about tie breaker map pool

* Fix PICNIC lacking tie breaker maps

* Only link in bracket when tournament has started

* Styled tournament roster inputs

* Prefer IGN in tournament match page

* ModeProgressIndicator

* Some conditional rendering

* Match action initial + better error display

* Persist bestOf in DB

* Resolve best of ahead of time

* Move brackets-manager to core

* Score reporting works

* Clear winner on score report

* ModeProgressIndicator: highlight winners

* Fix inconsistent input

* Better text when submitting match

* mapCountPlayedInSetWithCertainty that works

* UNDO_REPORT_SCORE implemented

* Permission check when starting tournament

* Remove IGN from upsert

* View match results page

* Source in DB

* Match page waiting for teams

* Move tournament bracket to feature folder

* REOPEN_MATCH initial

* Handle proper resetting of match

* Inline bracket-manager

* Syncify

* Transactions

* Handle match is locked gracefully

* Match page auto refresh

* Fix match refresh called "globally"

* Bracket autoupdate

* Move fillWithNullTillPowerOfTwo to utils with testing

* Fix map lists not visible after tournament started

* Optimize match events

* Show UI while in progress to members

* Fix start tournament alert not being responsive

* Teams can check in

* Fix map list 400

* xxx -> TODO

* Seeds page

* Remove map icons for team page

* Don't display link to seeds after tournament has started

* Admin actions initial

* Change captain admin action

* Make all hooks ts

* Admin actions functioning

* Fix validate error not displaying in CatchBoundary

* Adjust validate args order

* Remove admin loader

* Make delete team button menancing

* Only include checked in teams to bracket

* Optimize to.id route loads

* Working show map list generator toggle

* Update full tournaments flow

* Make full tournaments work with many start times

* Handle undefined in crud

* Dynamic stage banner

* Handle default strat if map list generation fails

* Fix crash on brackets if less than 2 teams

* Add commented out test for reference

* Add TODO

* Add players from team during register

* TrustRelationship

* Prefers not to host feature

* Last before merge

* Rename some vars

* More renames
2023-05-15 22:37:43 +03:00

154 lines
4.5 KiB
TypeScript

import * as React from "react";
import { Form } from "@remix-run/react";
import type {
TournamentLoaderData,
TournamentLoaderTeam,
} from "../../tournament/routes/to.$id";
import type { Unpacked } from "~/utils/types";
import { TOURNAMENT } from "../../tournament/tournament-constants";
import { SubmitButton } from "~/components/SubmitButton";
import { TeamRosterInputs } from "./TeamRosterInputs";
import type { TournamentMapListMap } from "~/modules/tournament-map-list-generator";
import { useTranslation } from "~/hooks/useTranslation";
import type { Result } from "./ScoreReporter";
export function ScoreReporterRosters({
teams,
position,
currentStageWithMode,
result,
}: {
teams: [TournamentLoaderTeam, TournamentLoaderTeam];
position: number;
currentStageWithMode: TournamentMapListMap;
result?: Result;
}) {
const [checkedPlayers, setCheckedPlayers] = React.useState<
[number[], number[]]
>(checkedPlayersInitialState(teams));
const [winnerId, setWinnerId] = React.useState<number | undefined>();
const presentational = Boolean(result);
return (
<Form method="post" className="width-full">
<div>
<TeamRosterInputs
teams={teams}
winnerId={winnerId}
setWinnerId={setWinnerId}
checkedPlayers={checkedPlayers}
setCheckedPlayers={setCheckedPlayers}
result={result}
/>
{!presentational ? (
<div className="tournament-bracket__during-match-actions__actions">
<input type="hidden" name="winnerTeamId" value={winnerId ?? ""} />
<input
type="hidden"
name="playerIds"
value={JSON.stringify(checkedPlayers.flat())}
/>
<input type="hidden" name="position" value={position} />
<input
type="hidden"
name="stageId"
value={currentStageWithMode.stageId}
/>
<input
type="hidden"
name="mode"
value={currentStageWithMode.mode}
/>
<input
type="hidden"
name="source"
value={currentStageWithMode.source}
/>
<ReportScoreButtons
checkedPlayers={checkedPlayers}
winnerName={winningTeam()}
currentStageWithMode={currentStageWithMode}
/>
</div>
) : null}
</div>
</Form>
);
function winningTeam() {
if (!winnerId) return;
if (teams[0].id === winnerId) return teams[0].name;
if (teams[1].id === winnerId) return teams[1].name;
throw new Error("No winning team matching the id");
}
}
// TODO: remember what previously selected for our team
function checkedPlayersInitialState([teamOne, teamTwo]: [
Unpacked<TournamentLoaderData["teams"]>,
Unpacked<TournamentLoaderData["teams"]>
]): [number[], number[]] {
const result: [number[], number[]] = [[], []];
if (teamOne.members.length === TOURNAMENT.TEAM_MIN_MEMBERS_FOR_FULL) {
result[0].push(...teamOne.members.map((member) => member.userId));
}
if (teamTwo.members.length === TOURNAMENT.TEAM_MIN_MEMBERS_FOR_FULL) {
result[1].push(...teamTwo.members.map((member) => member.userId));
}
return result;
}
function ReportScoreButtons({
checkedPlayers,
winnerName,
currentStageWithMode,
}: {
checkedPlayers: number[][];
winnerName?: string;
currentStageWithMode: TournamentMapListMap;
}) {
const { t } = useTranslation(["game-misc"]);
if (
!checkedPlayers.every(
(team) => team.length === TOURNAMENT.TEAM_MIN_MEMBERS_FOR_FULL
)
) {
return (
<p className="tournament-bracket__during-match-actions__amount-warning-paragraph">
Please choose exactly {TOURNAMENT.TEAM_MIN_MEMBERS_FOR_FULL}+
{TOURNAMENT.TEAM_MIN_MEMBERS_FOR_FULL} players to report score
</p>
);
}
if (!winnerName) {
return (
<p className="tournament-bracket__during-match-actions__amount-warning-paragraph">
Please select the winner of this map
</p>
);
}
return (
<div className="stack sm items-center">
<div className="tournament-bracket__during-match-actions__confirm-score-text">
Report <b>{winnerName}</b> win on{" "}
<b>
{t(`game-misc:MODE_LONG_${currentStageWithMode.mode}`)}{" "}
{t(`game-misc:STAGE_${currentStageWithMode.stageId}`)}
</b>
?
</div>
<SubmitButton size="tiny" _action="REPORT_SCORE">
Report
</SubmitButton>
</div>
);
}