From 1287fa4ad9f00060e322d2ff382251647c4ec76f Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Sun, 3 Apr 2022 10:35:07 +0300 Subject: [PATCH] Add chat to tournament matches --- app/components/Chat/Message.tsx | 5 +- app/components/Chat/index.tsx | 11 ++- .../tournament/DuringMatchActions.tsx | 90 +++++++++++-------- app/models/Tournament.server.ts | 1 + app/routes/to/$organization.$tournament.tsx | 2 + .../bracket.$bid.tsx | 29 +++--- app/utils/index.ts | 2 + prisma/seed/script.ts | 13 ++- 8 files changed, 98 insertions(+), 55 deletions(-) diff --git a/app/components/Chat/Message.tsx b/app/components/Chat/Message.tsx index 75c0a183b..37981f2a4 100644 --- a/app/components/Chat/Message.tsx +++ b/app/components/Chat/Message.tsx @@ -1,6 +1,7 @@ import clsx from "clsx"; import { ChatLoaderData } from "~/routes/chat"; -import { Unpacked } from "~/utils"; +import { Unpacked, ValueOf } from "~/utils"; +import { ChatProps } from "."; export function Message({ data, @@ -9,7 +10,7 @@ export function Message({ }: { data: Omit, "roomId" | "id">; sending?: boolean; - user: { info?: string; name: string }; + user: ValueOf; }) { return (
  • diff --git a/app/components/Chat/index.tsx b/app/components/Chat/index.tsx index 774b6345e..174bdf1c6 100644 --- a/app/components/Chat/index.tsx +++ b/app/components/Chat/index.tsx @@ -7,13 +7,12 @@ import { SpeechBubbleIcon } from "../icons/SpeechBubble"; import { Message } from "./Message"; import useChat from "./useChat"; -export function Chat({ - id, - users, -}: { +export interface ChatProps { id: string; - users: { [id: string]: { info?: string; name: string } }; -}) { + users: { [id: string]: { info?: string | null; name: string } }; +} + +export function Chat({ id, users }: ChatProps) { const user = useUser(); const { messages, diff --git a/app/components/tournament/DuringMatchActions.tsx b/app/components/tournament/DuringMatchActions.tsx index a5a2058ab..1271755a9 100644 --- a/app/components/tournament/DuringMatchActions.tsx +++ b/app/components/tournament/DuringMatchActions.tsx @@ -3,6 +3,7 @@ import invariant from "tiny-invariant"; import type { BracketModified } from "~/services/bracket"; import type { FindTournamentByNameForUrlI } from "~/services/tournament"; import { Unpacked } from "~/utils"; +import { Chat } from "../Chat"; import { SubmitButton } from "../SubmitButton"; import { ActionSectionWrapper } from "./ActionSectionWrapper"; import { DuringMatchActionsRosters } from "./DuringMatchActionsRosters"; @@ -44,41 +45,60 @@ export function DuringMatchActions({ ]; return ( -
    - - {currentPosition > 1 && ( -
    - - - -
    - - Undo last score - -
    -
    + <> + [ + m.member.id, + { + name: m.member.discordName, + info: m.member.friendCode, + }, + ]) )} -
    - - - -
    + /> +
    + + {currentPosition > 1 && ( +
    + + + +
    + + Undo last score + +
    +
    + )} +
    + + + +
    + ); } diff --git a/app/models/Tournament.server.ts b/app/models/Tournament.server.ts index 7aba0bcca..bca9cf127 100644 --- a/app/models/Tournament.server.ts +++ b/app/models/Tournament.server.ts @@ -82,6 +82,7 @@ export async function findByNameForUrl({ discordName: true, discordId: true, discordDiscriminator: true, + friendCode: true, }, }, }, diff --git a/app/routes/to/$organization.$tournament.tsx b/app/routes/to/$organization.$tournament.tsx index addb817bd..87a1dcc81 100644 --- a/app/routes/to/$organization.$tournament.tsx +++ b/app/routes/to/$organization.$tournament.tsx @@ -26,6 +26,7 @@ import { useUser } from "~/hooks/common"; import tournamentStylesUrl from "../../styles/tournament.css"; import * as React from "react"; import { isTournamentAdmin } from "~/core/tournament/validators"; +import { chatRoute } from "~/utils/urls"; export const links: LinksFunction = () => { return [{ rel: "stylesheet", href: tournamentStylesUrl }]; @@ -81,6 +82,7 @@ export const meta: MetaFunction = (props) => { }; export const unstable_shouldReload: ShouldReloadFunction = (data) => { + if (data.submission?.action === chatRoute()) return false; const action = data.submission?.formData.get("_action"); if (!action) return true; return !["REPORT_SCORE", "UNDO_REPORT_SCORE"].includes(String(action)); diff --git a/app/routes/to/$organization.$tournament/bracket.$bid.tsx b/app/routes/to/$organization.$tournament/bracket.$bid.tsx index ab74baa62..5333a1312 100644 --- a/app/routes/to/$organization.$tournament/bracket.$bid.tsx +++ b/app/routes/to/$organization.$tournament/bracket.$bid.tsx @@ -1,4 +1,9 @@ -import { LinksFunction, LoaderFunction, Outlet } from "remix"; +import { + LinksFunction, + LoaderFunction, + Outlet, + ShouldReloadFunction, +} from "remix"; import { ActionFunction, json, useMatches } from "remix"; import invariant from "tiny-invariant"; import { z } from "zod"; @@ -17,6 +22,7 @@ import { } from "~/utils"; import { useUser } from "~/hooks/common"; import { useBracketDataWithEvents } from "~/hooks/useBracketDataWithEvents"; +import { chatRoute } from "~/utils/urls"; export const links: LinksFunction = () => { return [{ rel: "stylesheet", href: styles }]; @@ -104,13 +110,15 @@ export const action: ActionFunction = async ({ } }; -const typedJson = (args: BracketModified) => json(args); +export const unstable_shouldReload: ShouldReloadFunction = (data) => { + return data.submission?.action !== chatRoute(); +}; export const loader: LoaderFunction = async ({ params }) => { invariant(typeof params.bid === "string", "Expected params.bid to be string"); const bracket = await bracketById(params.bid); - return typedJson(bracket); + return json(bracket); }; // TODO: make bracket a bit smaller @@ -124,18 +132,17 @@ export default function BracketTabWrapper() { team.members.some(({ member }) => member.id === user?.id) ); + const winnersRounds = data.rounds.filter((round) => round.side === "winners"); + const losersRounds = data.rounds.filter((round) => round.side === "losers"); + return (
    - round.side === "winners")} - ownTeamName={ownTeam?.name} - /> - round.side === "losers")} - ownTeamName={ownTeam?.name} - /> + + {losersRounds.length > 0 ? ( + + ) : null}
    ); } diff --git a/app/utils/index.ts b/app/utils/index.ts index cea21f9f7..da45e3103 100644 --- a/app/utils/index.ts +++ b/app/utils/index.ts @@ -182,6 +182,8 @@ export type Unpacked = T extends (infer U)[] ? U : T; +export type ValueOf = T[keyof T]; + export type MyReducerAction< K extends string, T extends Record | undefined = undefined diff --git a/prisma/seed/script.ts b/prisma/seed/script.ts index 9e7541c92..ef2eabde1 100644 --- a/prisma/seed/script.ts +++ b/prisma/seed/script.ts @@ -147,7 +147,7 @@ export async function seed(variation?: SeedVariations) { userIds: string[], loggedInUserId: string ) { - const userIdsCopy = [...userIds]; + const userIdsCopy = [...userIds].filter((id) => id !== NZAP_UUID); const mockTeams = [ "Team Olive", "Chimera", @@ -234,6 +234,17 @@ export async function seed(variation?: SeedVariations) { }, }); } + + if (team.name === "Last Minute") { + await prisma.tournamentTeamMember.create({ + data: { + memberId: NZAP_UUID, + teamId: team.id, + captain: false, + tournamentId, + }, + }); + } } }