Repository navigation
feat(scout-for-lol): add the Matchup page to the app #5560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shepherdjerred
wants to merge
3
commits into
main
Choose a base branch
from
scout-matchup-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,194
−70
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
packages/scout-for-lol/packages/app/src/components/matchup/matchup-hero.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import type { Lane } from "@scout-for-lol/data"; | ||
| import { Chip } from "@scout-for-lol/design-system/components/surfaces/chip"; | ||
| import { ChampionFace } from "@scout-for-lol/design-system/domain/profile/champion-face"; | ||
| import { DuelHero } from "@scout-for-lol/design-system/domain/profile/duel-hero"; | ||
| import { Search } from "lucide-react"; | ||
| import { useSpaLink } from "#src/hooks/use-spa-link.ts"; | ||
| import { laneLine } from "#src/lib/matchup/matchup-page.ts"; | ||
| import { matchupPath } from "#src/lib/matchup/matchup-path.ts"; | ||
|
|
||
| export type MatchupSide = { championId: number; name: string }; | ||
|
|
||
| function OtherSide(props: { side: MatchupSide; to: string }) { | ||
| const link = useSpaLink(props.to); | ||
| return ( | ||
| <Chip href={link.href} onClick={link.onClick}> | ||
| <ChampionFace champion={props.side.championId} size={26} alt="" /> | ||
| I'm playing {props.side.name} | ||
| </Chip> | ||
| ); | ||
| } | ||
|
|
||
| function ChangeMatchup(props: { to: string }) { | ||
| const link = useSpaLink(props.to); | ||
| return ( | ||
| <Chip variant="ghost" href={link.href} onClick={link.onClick}> | ||
| <Search aria-hidden="true" size={18} /> | ||
| Change matchup | ||
| </Chip> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * The lead panel: the two champions facing each other, which side the viewer | ||
| * plays (the other side is a link to the same matchup from there) and the lane. | ||
| */ | ||
| export function MatchupHero(props: { | ||
| champion: MatchupSide; | ||
| opponent: MatchupSide; | ||
| lane: Lane; | ||
| }) { | ||
| const { champion, opponent, lane } = props; | ||
| return ( | ||
| <DuelHero | ||
| aria-labelledby="matchup-h" | ||
| start={{ champion: champion.championId }} | ||
| end={{ champion: opponent.championId }} | ||
| > | ||
| <h1 | ||
| id="matchup-h" | ||
| className="m-0 font-display text-4xl leading-[1.05] font-bold [overflow-wrap:anywhere] sm:text-5xl" | ||
| > | ||
| {champion.name}{" "} | ||
| <span className="font-medium text-scout-subtle">against</span>{" "} | ||
| {opponent.name} | ||
| </h1> | ||
| <div className="mt-4 flex flex-wrap justify-center gap-2"> | ||
| <Chip pressed> | ||
| <ChampionFace champion={champion.championId} size={26} alt="" /> | ||
| I'm playing {champion.name} | ||
| </Chip> | ||
| <OtherSide | ||
| side={opponent} | ||
| to={matchupPath(opponent.championId, champion.championId, lane)} | ||
| /> | ||
| <ChangeMatchup to={`/champions/${champion.championId.toString()}`} /> | ||
| </div> | ||
| <p className="mt-3.5 mb-0 text-scout-subtle">{laneLine(lane)}</p> | ||
| </DuelHero> | ||
| ); | ||
| } |
70 changes: 70 additions & 0 deletions
70
packages/scout-for-lol/packages/app/src/components/matchup/matchup-records.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import type { ReactNode } from "react"; | ||
| import { Panel } from "@scout-for-lol/design-system/components/surfaces/panel"; | ||
| import { GameSentenceRow } from "@scout-for-lol/design-system/domain/rows/game-sentence-row"; | ||
| import { | ||
| aheadLine, | ||
| recentRow, | ||
| recordLead, | ||
| type MatchupData, | ||
| type MatchupTally, | ||
| } from "#src/lib/matchup/matchup-page.ts"; | ||
|
|
||
| const HEADING = "m-0 font-display text-2xl leading-tight font-bold"; | ||
| const LEAD = "mt-3 mb-0 font-display text-3xl leading-tight text-balance"; | ||
| const SUB = "mt-2 mb-0 text-scout-subtle"; | ||
|
|
||
| function Record(props: { | ||
| heading: string; | ||
| id: string; | ||
| tally: MatchupTally; | ||
| who: "you" | "friends"; | ||
| children?: ReactNode; | ||
| }) { | ||
| const ahead = aheadLine(props.tally); | ||
| return ( | ||
| <Panel asChild> | ||
| <section aria-labelledby={props.id}> | ||
| <h2 id={props.id} className={HEADING}> | ||
| {props.heading} | ||
| </h2> | ||
| <p className={LEAD}>{recordLead(props.tally, props.who)}</p> | ||
| {ahead === undefined ? null : <p className={SUB}>{ahead}</p>} | ||
| {props.children} | ||
| </section> | ||
| </Panel> | ||
| ); | ||
| } | ||
|
|
||
| /** The viewer's record in the matchup and their newest games in it. */ | ||
| export function YourGames(props: { | ||
| matchup: MatchupData; | ||
| championId: number; | ||
| nowMs: number; | ||
| }) { | ||
| const { matchup } = props; | ||
| return ( | ||
| <Record heading="Your games" id="yours-h" tally={matchup.you} who="you"> | ||
| <ol className="m-0 mt-4 grid list-none gap-0.5 p-0 sm:-mx-3.5"> | ||
| {matchup.recent.map((game) => ( | ||
| <li key={game.matchId}> | ||
| <GameSentenceRow | ||
| {...recentRow(game, props.championId, props.nowMs)} | ||
| /> | ||
| </li> | ||
| ))} | ||
| </ol> | ||
| </Record> | ||
| ); | ||
| } | ||
|
|
||
| /** The record of everyone else in scope, one game per person and match. */ | ||
| export function FriendsRecord(props: { matchup: MatchupData }) { | ||
| return ( | ||
| <Record | ||
| heading="Friends" | ||
| id="friends-h" | ||
| tally={props.matchup.friends} | ||
| who="friends" | ||
| /> | ||
| ); | ||
| } |
52 changes: 52 additions & 0 deletions
52
packages/scout-for-lol/packages/app/src/components/matchup/matchup-shell.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { chipVariants } from "@scout-for-lol/design-system/components/surfaces/chip"; | ||
| import { EmptyState } from "@scout-for-lol/design-system/layout"; | ||
| import type { ReactNode } from "react"; | ||
| import { Link } from "react-router"; | ||
| import { DelayedLoadingState } from "#src/components/chrome/section-skeleton.tsx"; | ||
|
|
||
| /** The column the Matchup page sits in. */ | ||
| export function MatchupShell(props: { children: ReactNode }) { | ||
| return ( | ||
| <div className="mx-auto grid max-w-[1128px] gap-7 px-4 py-5 sm:px-8 sm:pt-8 sm:pb-14"> | ||
| {props.children} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export function MatchupLoading() { | ||
| return <DelayedLoadingState />; | ||
| } | ||
|
|
||
| /** The matchup could not be read: say so, and offer the retry. */ | ||
| export function MatchupUnavailable(props: { onRetry: () => void }) { | ||
| return ( | ||
| <EmptyState> | ||
| <h2 className="m-0 font-display text-2xl font-bold"> | ||
| This matchup could not be loaded | ||
| </h2> | ||
| <button | ||
| type="button" | ||
| className={chipVariants({ variant: "default" })} | ||
| onClick={props.onRetry} | ||
| > | ||
| Retry | ||
| </button> | ||
| </EmptyState> | ||
| ); | ||
| } | ||
|
|
||
| /** A champion the game does not have. */ | ||
| export function MatchupGone() { | ||
| return ( | ||
| <MatchupShell> | ||
| <EmptyState> | ||
| <h1 className="m-0 font-display text-2xl font-bold"> | ||
| This matchup is not available | ||
| </h1> | ||
| <Link to="/players" className={chipVariants({ variant: "default" })}> | ||
| Players | ||
| </Link> | ||
| </EmptyState> | ||
| </MatchupShell> | ||
| ); | ||
| } |
73 changes: 73 additions & 0 deletions
73
packages/scout-for-lol/packages/app/src/components/matchup/matchup-tips-panel.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { Panel } from "@scout-for-lol/design-system/components/surfaces/panel"; | ||
| import { GeneratedTipList } from "@scout-for-lol/design-system/domain/tips/generated-tip-list"; | ||
| import { GameFactProvider } from "@scout-for-lol/design-system/domain/tooltips/game-fact"; | ||
| import { loadGameFact } from "@scout-for-lol/data/game-facts/client.ts"; | ||
| import { useQuery } from "@tanstack/react-query"; | ||
| import { ZodError } from "zod"; | ||
| import { | ||
| loadChampionTips, | ||
| matchupTips, | ||
| type MatchupTips, | ||
| } from "#src/lib/matchup/matchup-tips.ts"; | ||
| import type { Lane } from "@scout-for-lol/data"; | ||
|
|
||
| /** The generated tips, led by the abilities they name; the other side is closed. */ | ||
| export function MatchupTipsPanel(props: { tips: MatchupTips }) { | ||
| return ( | ||
| <Panel asChild> | ||
| <section aria-labelledby="tips-h"> | ||
| <h2 | ||
| id="tips-h" | ||
| className="m-0 font-display text-2xl leading-tight font-bold" | ||
| > | ||
| Scout's tips | ||
| </h2> | ||
| <GameFactProvider loader={loadGameFact}> | ||
| <GeneratedTipList | ||
| className="mt-4" | ||
| tips={props.tips.tips} | ||
| reverse={props.tips.reverse} | ||
| /> | ||
| </GameFactProvider> | ||
| </section> | ||
| </Panel> | ||
| ); | ||
| } | ||
|
|
||
| type Side = { key: string; name: string }; | ||
|
|
||
| /** | ||
| * Reads both champions' tips files and shows the matchup's tips, or nothing | ||
| * while they load or when the generated matrix has none for this pair. A | ||
| * download that fails leaves the page without tips; a file that does not match | ||
| * its schema is a broken contract and fails loudly. | ||
| */ | ||
| export function MatchupTipsSection(props: { | ||
| champion: Side; | ||
| opponent: Side; | ||
| lane: Lane; | ||
| }) { | ||
| const { champion, opponent, lane } = props; | ||
| const tips = useQuery({ | ||
| queryKey: ["matchup-tips", champion.key, opponent.key, lane], | ||
| staleTime: Infinity, | ||
| retry: (count, error) => !(error instanceof ZodError) && count < 2, | ||
| queryFn: async () => { | ||
| const [championFile, opponentFile] = await Promise.all([ | ||
| loadChampionTips(champion.key), | ||
| loadChampionTips(opponent.key), | ||
| ]); | ||
| return ( | ||
| matchupTips({ | ||
| champion: { ...champion, file: championFile }, | ||
| opponent: { ...opponent, file: opponentFile }, | ||
| lane, | ||
| }) ?? null | ||
| ); | ||
| }, | ||
| }); | ||
| if (tips.error instanceof ZodError) throw tips.error; | ||
| return tips.data === undefined || tips.data === null ? null : ( | ||
| <MatchupTipsPanel tips={tips.data} /> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surface file-identity contract errors as well as schema errors.
If
Ahri.jsonpasses schema validation but declares another champion,loadChampionTips()throws a plainError. This guard does not rethrow that error. The query retries, then the section silently disappears.Give schema and file-identity failures a shared contract-error classification. Do not retry those failures, and rethrow them here. Keep download failures and missing files on their existing paths.
As per coding guidelines, “Internal contract violations fail loudly.”
Source: Coding guidelines