From f86b0ea533c0083ddca93752c0e5274231002001 Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Wed, 29 Dec 2021 08:50:41 +0200 Subject: [PATCH] Extract component --- app/components/tournament/BracketActions.tsx | 75 +----------------- .../tournament/DuringMatchActions.tsx | 79 +++++++++++++++++++ 2 files changed, 81 insertions(+), 73 deletions(-) create mode 100644 app/components/tournament/DuringMatchActions.tsx diff --git a/app/components/tournament/BracketActions.tsx b/app/components/tournament/BracketActions.tsx index a8f9b33b7..e9c74f964 100644 --- a/app/components/tournament/BracketActions.tsx +++ b/app/components/tournament/BracketActions.tsx @@ -1,15 +1,12 @@ -import { useState } from "react"; import { useLoaderData, useMatches } from "remix"; import invariant from "tiny-invariant"; -import { resolveHostInfo } from "~/core/tournament/utils"; import type { BracketModified, FindTournamentByNameForUrlI, } from "~/services/tournament"; -import { Unpacked } from "~/utils"; import { useUser } from "~/utils/hooks"; -import { Button } from "../Button"; import { ActionSectionWrapper } from "./ActionSectionWrapper"; +import { DuringMatchActions } from "./DuringMatchActions"; // 2) set up UI // - 1) Add *fc* 2) Host/join room with pass XXXX 3) Done @@ -19,7 +16,7 @@ import { ActionSectionWrapper } from "./ActionSectionWrapper"; // - Select players who played with radio boxes if team.length > min_roster_length // - Report -export function BracketActions() { +export function WaitingForMatchActions() { const data = useLoaderData(); const user = useUser(); const [, parentRoute] = useMatches(); @@ -106,71 +103,3 @@ export function BracketActions() { ); } - -function DuringMatchActions({ - ownTeam, - currentMatch, -}: { - ownTeam: Unpacked; - currentMatch: Unpacked["matches"]>; -}) { - const [, parentRoute] = useMatches(); - const { teams, seeds } = parentRoute.data as FindTournamentByNameForUrlI; - const [joinedRoom, setJoinedRoom] = useState( - (currentMatch.score?.[0] ?? 0) > 0 || (currentMatch.score?.[1] ?? 0) > 0 - ); - - const opponentTeam = teams.find( - (team) => - [currentMatch.participants?.[0], currentMatch.participants?.[1]].includes( - team.name - ) && team.id !== ownTeam.id - ); - invariant(opponentTeam, "opponentTeam is undefined"); - - if (joinedRoom) { - return ( - -

Opponent: {opponentTeam.name}

-
scores map etc.
-
- ); - } - - const { weHost, friendCodeToAdd, roomPass } = resolveHostInfo({ - ourTeam: ownTeam, - theirTeam: opponentTeam, - seeds, - }); - - 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/DuringMatchActions.tsx b/app/components/tournament/DuringMatchActions.tsx new file mode 100644 index 000000000..23a158c66 --- /dev/null +++ b/app/components/tournament/DuringMatchActions.tsx @@ -0,0 +1,79 @@ +import { useState } from "react"; +import { useMatches } from "remix"; +import invariant from "tiny-invariant"; +import { resolveHostInfo } from "~/core/tournament/utils"; +import type { + BracketModified, + FindTournamentByNameForUrlI, +} from "~/services/tournament"; +import { Unpacked } from "~/utils"; +import { Button } from "../Button"; +import { ActionSectionWrapper } from "./ActionSectionWrapper"; + +export function DuringMatchActions({ + ownTeam, + currentMatch, +}: { + ownTeam: Unpacked; + currentMatch: Unpacked["matches"]>; +}) { + const [, parentRoute] = useMatches(); + const { teams, seeds } = parentRoute.data as FindTournamentByNameForUrlI; + const [joinedRoom, setJoinedRoom] = useState( + (currentMatch.score?.[0] ?? 0) > 0 || (currentMatch.score?.[1] ?? 0) > 0 + ); + + const opponentTeam = teams.find( + (team) => + [currentMatch.participants?.[0], currentMatch.participants?.[1]].includes( + team.name + ) && team.id !== ownTeam.id + ); + invariant(opponentTeam, "opponentTeam is undefined"); + + if (joinedRoom) { + return ( + +

Opponent: {opponentTeam.name}

+
scores map etc.
+
+ ); + } + + const { weHost, friendCodeToAdd, roomPass } = resolveHostInfo({ + ourTeam: ownTeam, + theirTeam: opponentTeam, + seeds, + }); + + 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. +
+
+ ); +}