-
Notifications
You must be signed in to change notification settings - Fork 0
#287 Auto-fill faction field on match results if player faction is known #299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { useEffect } from 'react'; | ||
| import { useEffect, useMemo } from 'react'; | ||
| import { useFormContext } from 'react-hook-form'; | ||
|
|
||
| import { TournamentPairingId } from '~/api'; | ||
| import { Tournament, TournamentPairingId } from '~/api'; | ||
| import { FormField } from '~/components/generic/Form'; | ||
| import { InputSelect } from '~/components/generic/InputSelect'; | ||
| import { InputText } from '~/components/generic/InputText'; | ||
|
|
@@ -12,36 +12,62 @@ import styles from './TournamentPlayerFields.module.scss'; | |
|
|
||
| export interface TournamentPlayerFieldsProps { | ||
| tournamentPairingId: TournamentPairingId; | ||
| tournament?: Tournament | null; | ||
| } | ||
|
|
||
| export const TournamentPlayerFields = ({ | ||
| tournamentPairingId, | ||
| tournament, | ||
| }: TournamentPlayerFieldsProps): JSX.Element => { | ||
| const { setValue, watch } = useFormContext(); | ||
| const { player0UserId, player1UserId } = watch(); | ||
| const player0UserId = watch('player0UserId'); | ||
| const player1UserId = watch('player1UserId'); | ||
| const player0Faction = watch('details.player0Faction'); | ||
| const player1Faction = watch('details.player1Faction'); | ||
|
|
||
| const { data: selectedPairing } = useGetTournamentPairing({ id: tournamentPairingId }); | ||
|
|
||
| const player0Label = selectedPairing?.tournamentCompetitor0 ? `${selectedPairing.tournamentCompetitor0.displayName} Player` : 'Player 1'; | ||
| const player1Label = selectedPairing?.tournamentCompetitor1 ? `${selectedPairing.tournamentCompetitor1.displayName} Player` : 'Bye Placeholder'; | ||
| const player0Label = tournament?.useTeams && selectedPairing?.tournamentCompetitor0 ? `${selectedPairing.tournamentCompetitor0.displayName} Player` : 'Player 1'; | ||
| const player1Label = tournament?.useTeams && selectedPairing?.tournamentCompetitor1 ? `${selectedPairing.tournamentCompetitor1.displayName} Player` : 'Player 2'; | ||
ianpaschal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const player0Options = getCompetitorPlayerOptions(selectedPairing?.tournamentCompetitor0); | ||
| const player1Options = getCompetitorPlayerOptions(selectedPairing?.tournamentCompetitor1); | ||
|
Comment on lines
33
to
34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial
Proposed fix- const player0Options = getCompetitorPlayerOptions(selectedPairing?.tournamentCompetitor0);
- const player1Options = getCompetitorPlayerOptions(selectedPairing?.tournamentCompetitor1);
+ const player0Options = useMemo(
+ () => getCompetitorPlayerOptions(selectedPairing?.tournamentCompetitor0),
+ [selectedPairing?.tournamentCompetitor0],
+ );
+ const player1Options = useMemo(
+ () => getCompetitorPlayerOptions(selectedPairing?.tournamentCompetitor1),
+ [selectedPairing?.tournamentCompetitor1],
+ );Also applies to: 44-48 🤖 Prompt for AI Agents |
||
|
|
||
| const player0Registration = useMemo(() => ( | ||
| selectedPairing?.tournamentCompetitor0?.registrations.find((r) => r.userId === player0UserId) | ||
| ), [selectedPairing?.tournamentCompetitor0, player0UserId]); | ||
| const player1Registration = useMemo(() => ( | ||
| selectedPairing?.tournamentCompetitor1?.registrations.find((r) => r.userId === player1UserId) | ||
| ), [selectedPairing?.tournamentCompetitor1, player1UserId]); | ||
|
|
||
| // Automatically set "Player 1" if possible | ||
| useEffect(() => { | ||
| if (player0Options && player0Options.length === 1 && player0UserId !== player0Options[0].value) { | ||
| setValue('player0UserId', player0Options[0].value); | ||
| } | ||
| }, [player0Options, player0UserId, setValue]); | ||
|
|
||
| // Automatically set "Player 1" faction if possible | ||
| useEffect(() => { | ||
| if (player0Registration && player0Registration.factions.length > 0 && !player0Faction) { | ||
| setValue('details.player0Faction', player0Registration.factions[0]); | ||
| } | ||
| }, [player0Registration, player0Faction, setValue]); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Automatically set "Player 2" if possible | ||
| useEffect(() => { | ||
| if (player1Options && player1Options.length === 1 && player1UserId !== player1Options[0].value) { | ||
| setValue('player1UserId', player1Options[0].value); | ||
| } | ||
| }, [player1Options, player1UserId, setValue]); | ||
|
|
||
| // Automatically set "Player 2" faction if possible | ||
| useEffect(() => { | ||
| if (player1Registration && player1Registration.factions.length > 0 && !player1Faction) { | ||
| setValue('details.player1Faction', player1Registration.factions[0]); | ||
| } | ||
| }, [player1Registration, player1Faction, setValue]); | ||
ianpaschal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (!selectedPairing) { | ||
| return <div>Loading...</div>; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.