Fix not able to select winner aftr reporting score

This commit is contained in:
Kalle (Sendou)
2022-01-05 20:51:58 +02:00
parent 700ed935cc
commit 3c99572923
2 changed files with 10 additions and 6 deletions

View File

@@ -16,11 +16,14 @@ export function SubmitButton(
const [showSuccess, setShowSuccess] = useTimeoutState(false);
useEffect(() => {
if ((!successText && !onSuccess) || actionData?.ok !== actionType) return;
// did this submit button's action happen?
if (actionData?.ok !== actionType) return;
// this is essentially to ensure this only fires once per mutation
if (transition.type !== "actionReload") return;
onSuccess?.();
setShowSuccess(true);
}, [actionData]);
}, [actionData?.ok, transition.type]);
const isLoading = (): boolean => {
// is there an action happening at the moment?

View File

@@ -21,7 +21,7 @@ export function DuringMatchActionsRosters({
const [checkedPlayers, setCheckedPlayers] = React.useState<
[string[], string[]]
>(checkedPlayersInitialState([ownTeam, opponentTeam]));
const [winnerId, setWinnerId] = React.useState<string | null>(null);
const [winnerId, setWinnerId] = React.useState<string | undefined>();
return (
<Form method="post" className="width-full">
@@ -35,8 +35,7 @@ export function DuringMatchActionsRosters({
type="radio"
id={team.id}
name="winnerTeamId"
value={team.id}
onChange={(e) => setWinnerId(e.currentTarget.value)}
onChange={() => setWinnerId(team.id)}
checked={winnerId === team.id}
/>
<Label className="mb-0 ml-2" htmlFor={team.id}>
@@ -88,6 +87,7 @@ export function DuringMatchActionsRosters({
<div className="tournament-bracket__during-match-actions__actions">
<input type="hidden" name="_action" value="REPORT_SCORE" />
<input type="hidden" name="matchId" value={matchId} />
<input type="hidden" name="winnerTeamId" value={winnerId ?? ""} />
<input
type="hidden"
name="playerIds"
@@ -97,7 +97,7 @@ export function DuringMatchActionsRosters({
<ReportScoreButtons
checkedPlayers={checkedPlayers}
winnerName={winningTeam()}
clearWinner={() => setWinnerId(null)}
clearWinner={() => setWinnerId(undefined)}
/>
</div>
</div>
@@ -113,6 +113,7 @@ export function DuringMatchActionsRosters({
}
}
// TODO: remember what previously selected for our team
function checkedPlayersInitialState([teamOne, teamTwo]: [
Unpacked<FindTournamentByNameForUrlI["teams"]>,
Unpacked<FindTournamentByNameForUrlI["teams"]>