From 4f4473b3554e9325f424f671c01b63ebede21cc3 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Tue, 8 Feb 2022 17:49:40 +0200 Subject: [PATCH] Match over info UI --- app/components/play/MapList.tsx | 4 +-- app/models/LFGMatch.server.ts | 14 ++++---- app/routes/play/match.$id.tsx | 59 ++++++++++++++++++++++++++++----- app/styles/play-match.css | 48 ++++++++++++++++++++++++++- 4 files changed, 106 insertions(+), 19 deletions(-) diff --git a/app/components/play/MapList.tsx b/app/components/play/MapList.tsx index 6240ad47b..92b507a6d 100644 --- a/app/components/play/MapList.tsx +++ b/app/components/play/MapList.tsx @@ -21,9 +21,7 @@ interface MapListProps { }; } export function MapList({ mapList, canSubmitScore, groupIds }: MapListProps) { - const [winners, setWinners] = useState( - new Array(5).fill(null).map(() => "5f31654d-977b-402b-817a-6f20cd933aa5") - ); + const [winners, setWinners] = useState([]); const updateWinners = (winnerId: string, index: number) => { const newWinners = clone(winners); diff --git a/app/models/LFGMatch.server.ts b/app/models/LFGMatch.server.ts index 0a2c0b681..4a2725f12 100644 --- a/app/models/LFGMatch.server.ts +++ b/app/models/LFGMatch.server.ts @@ -24,20 +24,20 @@ export function findById(id: string) { } export function reportScore({ - matchId, - winnerIds, + UNSAFE_matchId, + UNSAFE_winnerIds, }: { - matchId: string; - winnerIds: string[]; + UNSAFE_matchId: string; + UNSAFE_winnerIds: string[]; }) { // https://stackoverflow.com/a/26715934 return db.$executeRawUnsafe(` update "LfgGroupMatchStage" as lfg set "winnerGroupId" = lfg2.winner_id from (values - ${winnerIds - .map((winnerId, i) => `('${matchId}', ${i + 1}, '${winnerId}')`) - .join(",")} + ${UNSAFE_winnerIds.map( + (winnerId, i) => `('${UNSAFE_matchId}', ${i + 1}, '${winnerId}')` + ).join(",")} ) as lfg2(lfg_group_match_id, "order", winner_id) where lfg2.lfg_group_match_id = lfg."lfgGroupMatchId" and lfg2.order = lfg.order; `); diff --git a/app/routes/play/match.$id.tsx b/app/routes/play/match.$id.tsx index 08b7c6814..f7b99defa 100644 --- a/app/routes/play/match.$id.tsx +++ b/app/routes/play/match.$id.tsx @@ -1,4 +1,5 @@ import { Mode } from "@prisma/client"; +import clsx from "clsx"; import { ActionFunction, Form, @@ -14,6 +15,8 @@ import invariant from "tiny-invariant"; import { z } from "zod"; import { Avatar } from "~/components/Avatar"; import { Button } from "~/components/Button"; +import { CheckmarkIcon } from "~/components/icons/Checkmark"; +import { ModeImage } from "~/components/ModeImage"; import { MapList } from "~/components/play/MapList"; import { DISCORD_URL } from "~/constants"; import * as LFGGroup from "~/models/LFGGroup.server"; @@ -75,8 +78,8 @@ export const action: ActionFunction = async ({ request, context }) => { case "REPORT_SCORE": { validate(ownGroup.matchId, "No match for the group"); await LFGMatch.reportScore({ - matchId: ownGroup.matchId, - winnerIds: data.winnerIds, + UNSAFE_matchId: ownGroup.matchId, + UNSAFE_winnerIds: data.winnerIds, }); break; } @@ -111,7 +114,7 @@ interface LFGMatchLoaderData { winner?: number; }[]; /** The final score. Shown if match is concluded */ - score?: [number, number]; + scores?: [number, number]; } export const loader: LoaderFunction = async ({ params, context }) => { @@ -154,7 +157,7 @@ export const loader: LoaderFunction = async ({ params, context }) => { })), }; }); - const score = match.stages[0].winnerGroupId + const scores = match.stages[0].winnerGroupId ? match.stages.reduce( (acc: [number, number], stage) => { if (!stage.winnerGroupId) return acc; @@ -170,7 +173,7 @@ export const loader: LoaderFunction = async ({ params, context }) => { isRanked, isOwnMatch, groups, - score, + scores, mapList: match.stages .map(({ stage, winnerGroupId }) => { const winner = () => { @@ -183,7 +186,7 @@ export const loader: LoaderFunction = async ({ params, context }) => { winner: winner(), }; }) - .filter((stage) => !score || typeof stage.winner === "number"), + .filter((stage) => !scores || typeof stage.winner === "number"), }); }; @@ -199,7 +202,7 @@ export default function LFGMatchPage() { return (
{g.members.map((user) => (
@@ -209,6 +212,15 @@ export default function LFGMatchPage() {
))} + {data.scores && ( +
+ {data.scores[i]} +
+ )}
); })} @@ -220,6 +232,37 @@ export default function LFGMatchPage() { #match-meetup channel. )} + {data.scores && ( +
+ {data.mapList.map((stage) => { + return ( + <> +
+ +
+
+ + {stage.name} +
+
+ +
+ + ); + })} +
+ )} {!data.isRanked && (
@@ -239,7 +282,7 @@ export default function LFGMatchPage() {
)} - {!data.score && ( + {!data.scores && (