From 041f7a4945aa6958d34a1a9cd947dc3c663993e9 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Sat, 8 Jan 2022 21:20:41 +0200 Subject: [PATCH] Extract TeamRosterCheckboxes component --- .../tournament/DuringMatchActions.tsx | 133 +++++++----------- .../tournament/DuringMatchActionsRosters.tsx | 56 +++----- .../tournament/TeamRosterCheckboxes.tsx | 41 ++++++ app/styles/tournament-bracket.css | 5 +- 4 files changed, 109 insertions(+), 126 deletions(-) create mode 100644 app/components/tournament/TeamRosterCheckboxes.tsx diff --git a/app/components/tournament/DuringMatchActions.tsx b/app/components/tournament/DuringMatchActions.tsx index fcea940ad..a00f53fa0 100644 --- a/app/components/tournament/DuringMatchActions.tsx +++ b/app/components/tournament/DuringMatchActions.tsx @@ -1,5 +1,4 @@ -import React, { useState } from "react"; -import { Form, useMatches } from "remix"; +import { useMatches } from "remix"; import invariant from "tiny-invariant"; import { modesShortToLong } from "~/constants"; import { resolveHostInfo } from "~/core/tournament/utils"; @@ -8,9 +7,6 @@ import type { FindTournamentByNameForUrlI, } from "~/services/tournament"; import { modeToImageUrl, Unpacked } from "~/utils"; -import { Button } from "../Button"; -import { Label } from "../Label"; -import { SubmitButton } from "../SubmitButton"; import { ActionSectionWrapper } from "./ActionSectionWrapper"; import { DuringMatchActionsRosters } from "./DuringMatchActionsRosters"; @@ -25,11 +21,6 @@ export function DuringMatchActions({ }) { const [, parentRoute] = useMatches(); const { teams, seeds } = parentRoute.data as FindTournamentByNameForUrlI; - const [joinedRoom, setJoinedRoom] = useState( - true || - (currentMatch.score?.[0] ?? 0) > 0 || - (currentMatch.score?.[1] ?? 0) > 0 - ); const opponentTeam = teams.find( (team) => @@ -45,41 +36,47 @@ export function DuringMatchActions({ seeds, }); - if (joinedRoom) { - const currentPosition = - currentMatch.score?.reduce((acc, cur) => acc + cur, 1) ?? 1; - const currentStage = currentRound.stages.find( - (m) => m.position === currentPosition - ); - invariant(currentStage, "currentStage is undefined"); - const { stage } = currentStage; + const currentPosition = + currentMatch.score?.reduce((acc, cur) => acc + cur, 1) ?? 1; + const currentStage = currentRound.stages.find( + (m) => m.position === currentPosition + ); + invariant(currentStage, "currentStage is undefined"); + const { stage } = currentStage; - const roundInfos: string[] = [ - `Pass ${roomPass} (${weHost ? "We" : "They"} host)`, - `Add ${friendCodeToAdd}`, - `${currentMatch.score?.join("-")} (Bo${currentRound.stages.length})`, - ]; + const roundInfos = [ + <> + Add {friendCodeToAdd} + , + <> + Pass {roomPass} ({weHost ? "We" : "They"} host) + , + <> + {currentMatch.score?.join("-")} (Best of{" "} + {currentRound.stages.length}) + , + ]; - return ( -
-
-
-

- - {modesShortToLong[stage.mode]} on {stage.name} -

-

Stage {currentPosition}

-
+ return ( +
+
+
+

+ + {modesShortToLong[stage.mode]} on {stage.name} +

+

Stage {currentPosition}

-
- {roundInfos.map((info) => ( -
{info}
- ))} -
- {/* +
+
+ {roundInfos.map((info) => ( +
{info}
+ ))} +
+ {/*
@@ -104,48 +101,14 @@ export function DuringMatchActions({
*/} - - - -
- ); - } - - return ( - -

- Opponent: {opponentTeam.name} -

-
    -
  1. Add FC: {friendCodeToAdd}
  2. - {weHost ? ( -
  3. -

    Your team hosting. Make a room (pass has to be {roomPass})

    -
  4. - ) : ( -
  5. -

    Their team is hosting. Join the room (pass: {roomPass})

    -
  6. - )} -
  7. -

    - Click{" "} - {" "} - when you have completed the steps above -

    -
  8. -
-
+ + + +
); } diff --git a/app/components/tournament/DuringMatchActionsRosters.tsx b/app/components/tournament/DuringMatchActionsRosters.tsx index 0990623bb..2e36e6561 100644 --- a/app/components/tournament/DuringMatchActionsRosters.tsx +++ b/app/components/tournament/DuringMatchActionsRosters.tsx @@ -6,6 +6,7 @@ import type { FindTournamentByNameForUrlI } from "~/services/tournament"; import { Unpacked } from "~/utils"; import { Label } from "../Label"; import { SubmitButton } from "../SubmitButton"; +import { TeamRosterCheckboxes } from "./TeamRosterCheckboxes"; export function DuringMatchActionsRosters({ ownTeam, @@ -42,45 +43,24 @@ export function DuringMatchActionsRosters({ Winner
-
- {team.members.map(({ member }) => ( -
- - setCheckedPlayers((players) => { - const newPlayers = clone(players); - if (checkedPlayers.flat().includes(member.id)) { - newPlayers[teamI] = newPlayers[teamI].filter( - (id) => id !== member.id - ); - } else { - newPlayers[teamI].push(member.id); - } + + setCheckedPlayers((players) => { + const newPlayers = clone(players); + if (checkedPlayers.flat().includes(playerId)) { + newPlayers[teamI] = newPlayers[teamI].filter( + (id) => id !== playerId + ); + } else { + newPlayers[teamI].push(playerId); + } - return newPlayers; - }) - } - />{" "} - -
- ))} -
+ return newPlayers; + }) + } + /> ))} diff --git a/app/components/tournament/TeamRosterCheckboxes.tsx b/app/components/tournament/TeamRosterCheckboxes.tsx new file mode 100644 index 000000000..7ff982b2d --- /dev/null +++ b/app/components/tournament/TeamRosterCheckboxes.tsx @@ -0,0 +1,41 @@ +import { TOURNAMENT_TEAM_ROSTER_MIN_SIZE } from "~/constants"; +import type { FindTournamentByNameForUrlI } from "~/services/tournament"; +import { Unpacked } from "~/utils"; +import { Label } from "../Label"; + +export function TeamRosterCheckboxes({ + team, + checkedPlayers, + handlePlayerClick, +}: { + team: Unpacked; + checkedPlayers: string[]; + handlePlayerClick: (playerId: string) => void; +}) { + return ( +
+ {team.members.map(({ member }) => ( +
+ handlePlayerClick(member.id)} + />{" "} + +
+ ))} +
+ ); +} diff --git a/app/styles/tournament-bracket.css b/app/styles/tournament-bracket.css index 66f37147e..c91318952 100644 --- a/app/styles/tournament-bracket.css +++ b/app/styles/tournament-bracket.css @@ -66,8 +66,8 @@ border-end-start-radius: var(--rounded); color: var(--tournaments-text); column-gap: var(--s-8); - font-size: var(--fonts-xxs); - font-weight: var(--bold); + font-size: var(--fonts-xs); + padding-block: 1px; } .tournament-bracket__infos__label { @@ -85,7 +85,6 @@ .tournament-bracket__during-match-actions { display: grid; - margin-top: var(--s-4); grid-template-areas: "img" "infos"