From a2dddca42e0b8338a0ae36529bb96ef7e1a63e1e Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Wed, 2 Mar 2022 00:25:45 +0200 Subject: [PATCH] Remove hardcoded Sendou --- app/routes/play/history.$id.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/routes/play/history.$id.tsx b/app/routes/play/history.$id.tsx index faff3f862..7d96ad4f6 100644 --- a/app/routes/play/history.$id.tsx +++ b/app/routes/play/history.$id.tsx @@ -37,6 +37,7 @@ interface MathHistoryLoaderData { stageCount: number; setWinRate: number; stageWinRate: number; + ownName: string; } export const loader: LoaderFunction = async ({ params }) => { @@ -45,6 +46,11 @@ export const loader: LoaderFunction = async ({ params }) => { const matches = await LFGMatch.findByUserId({ userId: params.id }); if (matches.length === 0) throw new Response(null, { status: 404 }); // TODO: don't show link if it would 404? + const ownUser = matches[0].groups + .flatMap((g) => g.members) + .find((m) => m.memberId === params.id); + invariant(ownUser, "Unexpected no ownUser"); + const mappedMatches = matches.map( (match): Unpacked => { const usersGroup = match.groups.find((g) => @@ -86,6 +92,7 @@ export const loader: LoaderFunction = async ({ params }) => { ); return json({ + ownName: ownUser.user.discordName, stageCount: mappedMatches.reduce( (acc, match) => match.score.our + match.score.their + acc, 0 @@ -114,7 +121,7 @@ export default function MatchHistoryPage() { return ( <>

- Sendou's SendouQ results + {data.ownName}'s SendouQ results

{data.matches.length} {data.matches.length === 1 ? "set" : "sets"}{" "}