Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import type { Lane } from "@scout-for-lol/data";
import { Chip } from "@scout-for-lol/design-system/components/surfaces/chip";
import { Panel } from "@scout-for-lol/design-system/components/surfaces/panel";
import { ChampionFace } from "@scout-for-lol/design-system/domain/profile/champion-face";
import {
laneLabel,
matchupGroups,
matchupLines,
type MatchupEntry,
} from "#src/lib/champions/champion-pages.ts";

/**
* The viewer's matchups in one lane: the ones they win and the ones they lose,
* each with the games behind it and how often they were ahead at 15 minutes.
* With no matchup to show in a lane it stays only when another lane can be
* chosen.
*/
export function MatchupsPanel(props: {
matchups: readonly MatchupEntry[];
lanes: readonly Lane[];
lane: Lane;
onLane: (lane: Lane) => void;
}) {
const groups = matchupGroups(props.matchups);
const hasMatchups = groups.good.length > 0 || groups.hard.length > 0;
if (!hasMatchups && props.lanes.length < 2) return null;
return (
<Panel asChild>
<section aria-labelledby="matchups-h">
<div className="flex flex-wrap items-center justify-between gap-x-4 gap-y-3">
<h2
id="matchups-h"
className="m-0 font-display text-2xl leading-tight font-bold"
>
Your matchups
</h2>
{props.lanes.length < 2 ? null : (
<div
role="group"
aria-label="Lane"
className="flex flex-wrap gap-2"
>
{props.lanes.map((lane) => (
<Chip
key={lane}
pressed={lane === props.lane}
onClick={() => {
props.onLane(lane);
}}
>
{laneLabel(lane)}
</Chip>
))}
</div>
)}
</div>
{groups.lead === undefined ? null : (
<p className="mt-3 mb-0 font-display text-3xl leading-tight text-balance">
{groups.lead}
</p>
)}
<div className="mt-5 grid gap-x-11 gap-y-5 sm:grid-cols-2">
<MatchupColumn heading="Does well against" entries={groups.good} />
<MatchupColumn
heading="Has a hard time against"
entries={groups.hard}
/>
</div>
</section>
</Panel>
);
}

function MatchupColumn(props: {
heading: string;
entries: readonly MatchupEntry[];
}) {
if (props.entries.length === 0) return null;
return (
<div>
<h3 className="m-0 text-[15px] leading-snug font-semibold text-scout-subtle">
{props.heading}
</h3>
<ul className="m-0 mt-1.5 grid list-none gap-0.5 p-0 sm:-mx-3">
{props.entries.map((entry) => (
<MatchupItem key={entry.opponent.championId} entry={entry} />
))}
</ul>
</div>
);
}

function MatchupItem(props: { entry: MatchupEntry }) {
const { you } = props.entry;
if (you === null)
throw new Error("Matchups listed an opponent the viewer has not faced");
const lines = matchupLines(you);
return (
<li className="flex items-center gap-3.5 py-[7px] pr-4 pl-3">
<ChampionFace
champion={props.entry.opponent.championId}
size={46}
alt=""
/>
<span className="grid min-w-0 flex-1 leading-snug">
<b className="font-display text-xl">{props.entry.opponent.name}</b>
<span className="text-scout-subtle">{lines.result}</span>
{lines.lane === undefined ? null : (
<span className="text-scout-subtle">{lines.lane}</span>
)}
</span>
</li>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { Panel } from "@scout-for-lol/design-system/components/surfaces/panel";
import { FriendRow } from "@scout-for-lol/design-system/domain/rows/friend-row";
import type { ReactNode } from "react";
import { useSpaLink } from "#src/hooks/use-spa-link.ts";
import {
formText,
type ComparisonRow,
} from "#src/lib/champions/champion-pages.ts";

/** Who is best on the champion: everyone with enough games, best win rate first. */
export function RankingPanel(props: {
championName: string;
rows: readonly ComparisonRow[];
controls: ReactNode;
}) {
return (
<Panel asChild>
<section aria-labelledby="ranking-h">
<h2
id="ranking-h"
className="m-0 font-display text-2xl leading-tight font-bold"
>
Who&apos;s best on {props.championName}
</h2>
<div className="mt-3">{props.controls}</div>
<ol className="m-0 mt-3.5 grid list-none gap-0.5 p-0 sm:-mx-3.5">
{props.rows.map((row, index) => (
<li key={`${row.guild.guildId}:${row.playerId.toString()}`}>
<RankingRow row={row} place={index + 1} />
</li>
))}
</ol>
</section>
</Panel>
);
}

function RankingRow(props: { row: ComparisonRow; place: number }) {
const { row } = props;
const link = useSpaLink(`/players/${row.playerId.toString()}`);
return (
<FriendRow
name={row.alias}
href={link.href}
onClick={link.onClick}
place={props.place}
you={row.viewerLinked}
latest={row.guild.name}
record={{
games: row.games,
winRate: row.winRate * 100,
form: formText(row),
}}
/>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { Panel } from "@scout-for-lol/design-system/components/surfaces/panel";
import { PersonInitial } from "@scout-for-lol/design-system/domain/profile/person-initial";
import { Link } from "react-router";
import {
compactPoints,
recordText,
type ComparisonRow,
} from "#src/lib/champions/champion-pages.ts";
import type { RouterOutputs } from "#src/lib/query/trpc.ts";

type MasteryRow =
RouterOutputs["consumerChampion"]["masteryLeaderboard"]["rows"][number];

/** Rows the mastery panel lists. */
export const MASTERY_LIMIT = 3;

const HEADING = "m-0 font-display text-2xl leading-tight font-bold";
const NAME = "font-display text-xl hover:text-scout-brand";
const YOU =
"flex-none rounded-full bg-scout-brand px-2.5 text-[13px] leading-5 font-bold text-scout-brand-ink";

/** People with fewer games than the ranking needs, with how those went. */
export function WarmingUp(props: { rows: readonly ComparisonRow[] }) {
return (
<Panel variant="open" asChild>
<section aria-labelledby="warming-h">
<h2 id="warming-h" className={HEADING}>
Still warming up
</h2>
<ul className="m-0 mt-3 grid list-none gap-1 p-0">
{props.rows.map((row) => (
<li
key={`${row.guild.guildId}:${row.playerId.toString()}`}
className="flex min-h-11 items-center gap-3"
>
<PersonInitial name={row.alias} size="s" you={row.viewerLinked} />
<Link
to={`/players/${row.playerId.toString()}`}
className={`${NAME} min-w-0 flex-1 text-scout-ink no-underline`}
>
<b>{row.alias}</b>
</Link>
<span className="text-scout-subtle">
{recordText(row.wins, row.losses)}
</span>
</li>
))}
</ul>
</section>
</Panel>
);
}

/** The people with the most mastery points on the champion. */
export function MasteryPanel(props: { rows: readonly MasteryRow[] }) {
return (
<Panel asChild>
<section aria-labelledby="mastery-h">
<h2 id="mastery-h" className={HEADING}>
Most mastery
</h2>
<ol className="m-0 mt-3.5 grid list-none gap-2 p-0">
{props.rows.slice(0, MASTERY_LIMIT).map((row) => (
<li
key={`${row.guild.guildId}:${row.playerId.toString()}`}
className="flex min-h-11 items-center gap-3"
>
<PersonInitial name={row.alias} size="s" you={row.viewerLinked} />
<span className="flex min-w-0 flex-1 items-center gap-2">
<Link
to={`/players/${row.playerId.toString()}`}
className={`${NAME} min-w-0 text-scout-ink no-underline`}
>
<b>{row.alias}</b>
</Link>
{row.viewerLinked ? <span className={YOU}>You</span> : null}
</span>
<span className="flex items-baseline gap-1.5">
<b className="font-display text-xl">
{compactPoints(row.points)}
</b>
<span className="text-scout-subtle">points</span>
</span>
</li>
))}
</ol>
</section>
</Panel>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { chipVariants } from "@scout-for-lol/design-system/components/surfaces/chip";
import { HeroPanel } from "@scout-for-lol/design-system/domain/profile/hero-panel";
import { PageState } from "@scout-for-lol/design-system/domain/profile/page-states";
import { Search } from "lucide-react";
import type { ReactNode } from "react";
import { Link } from "react-router";
import { RankingPanel } from "#src/components/champions/champion-ranking.tsx";
import { WarmingUp } from "#src/components/champions/champion-side.tsx";
import { ChampionsShell } from "#src/components/champions/champions-shell.tsx";
import { HeroWords } from "#src/components/champions/hero-words.tsx";
import {
championHeroLines,
type ComparisonRow,
} from "#src/lib/champions/champion-pages.ts";

/**
* A champion in the viewer's servers: the hero, who is best on it, who is still
* warming up and, in the slots the route fills, the matchups and mastery.
*/
export function ChampionView(props: {
championId: number;
name: string;
qualifyingGames: number;
qualified: readonly ComparisonRow[];
small: readonly ComparisonRow[];
/** More qualified rows exist than the page read. */
truncated: boolean;
servers: ReactNode;
matchups: ReactNode;
mastery: ReactNode;
}) {
if (props.qualified.length === 0 && props.small.length === 0) {
return (
<ChampionsShell>
{props.servers}
<PageState
kind="empty"
level={1}
id="champion-empty"
title={props.name}
lead={`Nobody in your servers has played ${props.name}`}
actions={
<Link
to="/champions"
className={chipVariants({ variant: "ghost" })}
>
Change champion
</Link>
}
/>
</ChampionsShell>
);
}
const lines = championHeroLines({
name: props.name,
qualifyingGames: props.qualifyingGames,
qualified: props.qualified,
small: props.small,
truncated: props.truncated,
});
const hasSide = props.small.length > 0 || props.mastery !== null;
return (
<ChampionsShell>
<HeroPanel
aria-labelledby="champion-h"
art={{ champion: props.championId }}
action={
<Link to="/champions" className={chipVariants({ variant: "float" })}>
<Search size={18} aria-hidden="true" />
Change champion
</Link>
}
>
<HeroWords
id="champion-h"
title={props.name}
lead={lines.lead}
sub={lines.sub}
/>
</HeroPanel>
<div
className={`grid items-start gap-7 ${hasSide ? "min-[1181px]:grid-cols-[minmax(0,1.5fr)_minmax(0,1fr)]" : ""}`}
>
<div className="grid min-w-0 gap-7">
{props.qualified.length === 0 ? props.servers : null}
{props.qualified.length === 0 ? null : (
<RankingPanel
championName={props.name}
rows={props.qualified}
controls={props.servers}
/>
)}
{props.matchups}
</div>
{hasSide ? (
<div className="grid min-w-0 gap-7">
{props.small.length === 0 ? null : <WarmingUp rows={props.small} />}
{props.mastery}
</div>
) : null}
</div>
</ChampionsShell>
);
}
Loading