From efefe01a4b62893edab5a09f027e717f8f4d8142 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Wed, 2 Mar 2022 17:24:01 +0200 Subject: [PATCH] "No results" not 404 if didn't play SendouQ yet --- app/models/User.server.ts | 4 ++++ app/routes/play/history.$id.tsx | 39 ++++++++++++++++++------------- app/styles/play-match-history.css | 6 +++++ 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/app/models/User.server.ts b/app/models/User.server.ts index 9542800cd..0a355683e 100644 --- a/app/models/User.server.ts +++ b/app/models/User.server.ts @@ -15,3 +15,7 @@ export function findTrusters(userId: string) { }, }); } + +export function findById(userId: string) { + return db.user.findUnique({ where: { id: userId } }); +} diff --git a/app/routes/play/history.$id.tsx b/app/routes/play/history.$id.tsx index 7d96ad4f6..736ca6dc5 100644 --- a/app/routes/play/history.$id.tsx +++ b/app/routes/play/history.$id.tsx @@ -8,6 +8,7 @@ import { } from "remix"; import { makeTitle, Unpacked } from "~/utils"; import * as LFGMatch from "~/models/LFGMatch.server"; +import * as User from "~/models/User.server"; import invariant from "tiny-invariant"; import styles from "~/styles/play-match-history.css"; import clsx from "clsx"; @@ -43,13 +44,11 @@ interface MathHistoryLoaderData { export const loader: LoaderFunction = async ({ params }) => { invariant(typeof params.id === "string", "Expected params.id to be string"); - 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 [matches, user] = await Promise.all([ + LFGMatch.findByUserId({ userId: params.id }), + User.findById(params.id), + ]); + if (!user) throw new Response(null, { status: 404 }); const mappedMatches = matches.map( (match): Unpacked => { @@ -92,7 +91,7 @@ export const loader: LoaderFunction = async ({ params }) => { ); return json({ - ownName: ownUser.user.discordName, + ownName: user.discordName, stageCount: mappedMatches.reduce( (acc, match) => match.score.our + match.score.their + acc, 0 @@ -123,14 +122,22 @@ export default function MatchHistoryPage() {

{data.ownName}'s SendouQ results

- - {data.matches.length} {data.matches.length === 1 ? "set" : "sets"}{" "} - played ({data.setWinRate}% winrate) - {" "} - •{" "} - - {data.stageCount} maps played ({data.stageWinRate}% winrate) - + {data.matches.length > 0 ? ( + <> + + {data.matches.length} {data.matches.length === 1 ? "set" : "sets"}{" "} + played ({data.setWinRate}% winrate) + {" "} + •{" "} + + {data.stageCount} maps played ({data.stageWinRate}% winrate) + + + ) : ( + + No matches played yet + + )} {data.matches.map((match) => { const currentDateString = new Date( match.createdAtTimestamp diff --git a/app/styles/play-match-history.css b/app/styles/play-match-history.css index 698a2f0a6..49b66b7d4 100644 --- a/app/styles/play-match-history.css +++ b/app/styles/play-match-history.css @@ -9,6 +9,12 @@ font-weight: var(--semi-bold); } +.play-match-history__no-matches { + color: var(--text-lighter); + font-size: var(--fonts-lg); + font-weight: var(--bold); +} + .play-match-history__date { border-block-end: 5px solid var(--theme-transparent); margin-block-end: var(--s-5);