Skip to content
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

Add user to many tournaments in a tournament #2001

Merged
merged 9 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions app/features/tournament-bracket/components/MatchActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,26 @@ export function MatchActions({
>(() => {
if (result) {
return [
result.participantIds.filter((id) =>
teams[0].members.some((member) => member.userId === id),
),
result.participantIds.filter((id) =>
teams[1].members.some((member) => member.userId === id),
),
result.participants
.filter((participant) =>
teams[0].members.some(
(member) =>
member.userId === participant.userId &&
(!participant.tournamentTeamId ||
teams[0].id === participant.tournamentTeamId),
),
)
.map((p) => p.userId),
result.participants
.filter((participant) =>
teams[1].members.some(
(member) =>
member.userId === participant.userId &&
(!participant.tournamentTeamId ||
teams[1].id === participant.tournamentTeamId),
),
)
.map((p) => p.userId),
];
}

Expand Down Expand Up @@ -340,7 +354,7 @@ function EditScoreForm({
return (
<fetcher.Form
method="post"
className="stack horizontal md justify-center"
className="stack horizontal md justify-center mt-6"
>
<input type="hidden" name="resultId" value={resultId} />
<input
Expand Down
4 changes: 3 additions & 1 deletion app/features/tournament-bracket/components/StartedMatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,9 @@ function StartedMatchTabs({
teams[1],
tournament.minMembersPerTeam,
),
result?.participantIds,
result?.participants
.map((p) => `${p.userId}-${p.tournamentTeamId}`)
.join(","),
result?.opponentOnePoints,
result?.opponentTwoPoints,
].join("-");
Expand Down
16 changes: 11 additions & 5 deletions app/features/tournament-bracket/components/TeamRosterInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,14 @@ function _TeamRoster({
);

const checkedInputPlayerIds = () => {
if (result?.participantIds && !revising) {
return result.participantIds;
if (result?.participants && !revising) {
return result.participants
.filter(
(participant) =>
!participant.tournamentTeamId ||
participant.tournamentTeamId === team.id,
)
.map((participant) => participant.userId);
}
if (editingRoster) return checkedPlayers.split(",").map(Number);

Expand Down Expand Up @@ -216,12 +222,12 @@ function _TeamRoster({
teamId={team.id}
checkedPlayers={checkedInputPlayerIds()}
presentational={!revising && (presentational || !editingRoster)}
handlePlayerClick={(playerId: number) => {
handlePlayerClick={(playerId) => {
if (!setCheckedPlayers) return;

setCheckedPlayers((oldPlayers) => {
const newPlayers = clone(oldPlayers);
if (oldPlayers.flat().includes(playerId)) {
if (oldPlayers[idx].includes(playerId)) {
newPlayers[idx] = newPlayers[idx].filter((id) => id !== playerId);
} else {
newPlayers[idx].push(playerId);
Expand Down Expand Up @@ -452,7 +458,7 @@ function TeamRosterInputsCheckboxes({
name="playerName"
disabled={mode() === "DISABLED" || mode() === "PRESENTATIONAL"}
value={member.id}
checked={checkedPlayers.flat().includes(member.id)}
checked={checkedPlayers.includes(member.id)}
onChange={() => handlePlayerClick(member.id)}
data-testid={`player-checkbox-${i}`}
/>{" "}
Expand Down
15 changes: 14 additions & 1 deletion app/features/tournament-bracket/core/Tournament.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1041,9 +1041,22 @@ export class Tournament {
teamMemberOfByUser(user: OptionalIdObject) {
if (!user) return null;

return this.ctx.teams.find((team) =>
const teams = this.ctx.teams.filter((team) =>
team.members.some((member) => member.userId === user.id),
);

let result: (typeof teams)[number] | null = null;
let latestCreatedAt = 0;
for (const team of teams) {
const member = team.members.find((member) => member.userId === user.id)!;

if (member.createdAt > latestCreatedAt) {
result = team;
latestCreatedAt = member.createdAt;
}
}

return result;
}

teamMemberOfProgressStatus(user: OptionalIdObject) {
Expand Down
Loading
Loading