diff --git a/web/src/app/maps/page.tsx b/web/src/app/maps/page.tsx index 851e7bb..3fe560d 100644 --- a/web/src/app/maps/page.tsx +++ b/web/src/app/maps/page.tsx @@ -11,7 +11,7 @@ export const metadata: Metadata = { export default function MapsPage({ searchParams }: PageProps<"/maps">) { return ( - + {searchParams.then((params) => ( ))} diff --git a/web/src/features/maps/MapImage.tsx b/web/src/features/maps/MapImage.tsx index 1cde58c..ba8745f 100644 --- a/web/src/features/maps/MapImage.tsx +++ b/web/src/features/maps/MapImage.tsx @@ -8,6 +8,7 @@ import { classNames } from "@/ui/classNames"; const sizes = { thumbnail: "h-10 w-14 rounded-md sm:h-12 sm:w-20", tile: "h-14 w-24 rounded-md sm:h-20 sm:w-36", + card: "aspect-video w-full rounded-none", banner: "h-36 w-full rounded-md lg:h-44", }; diff --git a/web/src/features/maps/MapList.tsx b/web/src/features/maps/MapList.tsx index 280a2da..ee9f3fd 100644 --- a/web/src/features/maps/MapList.tsx +++ b/web/src/features/maps/MapList.tsx @@ -2,7 +2,6 @@ // and one row per map with its picture, tier and world record. Staff who manage maps also get a "No runs yet" tab // and a "Map files" tab for uploading viewer files in bulk, and can set up a map by name before its first run. import { X } from "lucide-react"; -import Form from "next/form"; import type { CSSProperties } from "react"; import { api, type Schemas } from "@/api/client"; import { signedInPlayer } from "@/features/auth/signedInPlayer"; @@ -19,7 +18,6 @@ import { SearchField } from "@/ui/SearchField"; import { Link } from "@/ui/Link"; import { ChoiceBar } from "@/ui/ChoiceBar"; import { ChoiceMenu } from "@/ui/ChoiceMenu"; -import { classNames } from "@/ui/classNames"; import { LinkTabs } from "@/ui/LinkTabs"; import { Pager } from "@/ui/Pager"; import { TierBadge } from "@/ui/TierBadge"; @@ -206,56 +204,28 @@ export async function MapList({ params }: { params: MapListParams }) { }; return ( -
- {/* The title and how many maps there are, with the search beside them, as on the other boards. */} -
-
-

Maps

- {list && ( -

- - {number.format(list.stats.maps)} - {" "} - {list.stats.maps === 1 ? "map has" : "maps have"} a finished run. -

- )} -
-
- {/* Searching keeps the chosen tab, sort, style and completion filter. */} - {unplayed && } - {completion !== "all" && filterPlayer && ( - <> - - - - )} - {sort !== DEFAULT_SORT && ( - - )} - {requestedStyle && ( - - )} - {tier != null && } - - -
+
+

Maps

{list && ( href({ tier: choice })} - newestHref={href({ sort: "newest", tier: null, page: 1 })} + newestHref={href({ sort: "newest", page: 1 })} /> )} - {/* The menus and what they sort and filter, held close together and a step apart from the overview above. */} -
+
+ {!unplayed && ( <> @@ -303,99 +273,89 @@ export async function MapList({ params }: { params: MapListParams }) { {/* Staff only, out of the way of the menus everyone uses. */} {staff &&
{staffTabs}
}
+
- {/* With no results, the empty card below offers this instead. */} - {offerSetUp && list && list.maps.length > 0 && ( - - - No map on the list is called {typedName}. Its Manage view works - before anyone runs it, so its zones can be ready first. - + {/* With no results, the empty card below offers this instead. */} + {offerSetUp && list && list.maps.length > 0 && ( + + + No map on the list is called {typedName}. Its Manage view works + before anyone runs it, so its zones can be ready first. + + + Manage {typedName} + + + )} + + {unplayed ? ( + href({ page: p })} /> + ) : !list ? ( +

Maps couldn't be loaded. Try again in a moment.

+ ) : list.maps.length === 0 ? ( + + + {completion === "yes" + ? "No map here has been completed by this player." + : completion === "no" + ? "This player has completed every map here." + : q + ? "No map with a run has that name." + : tier != null + ? `No map with a run has tier ${tier}.` + : "No map has a finished run yet."} + + {offerSetUp && ( Manage {typedName} - - )} - - {unplayed ? ( - href({ page: p })} /> - ) : !list ? ( -

Maps couldn't be loaded. Try again in a moment.

- ) : list.maps.length === 0 ? ( - - - {completion === "yes" - ? "No map here has been completed by this player." - : completion === "no" - ? "This player has completed every map here." - : q - ? "No map with a run has that name." - : tier != null - ? `No map with a run has tier ${tier}.` - : "No map has a finished run yet."} - - {offerSetUp && ( - - Manage {typedName} - - )} - - ) : ( - <> -
-
-

- {q - ? `Maps matching “${q}”` - : tier != null - ? `Tier ${tier} maps` - : "All maps"} -

- {/* The style is the "Records in" menu's, just above. */} -

World record

-
- {/* Two columns read top to bottom, like the order they're in. Keyed by what's shown, so a new sort or - style remounts every row and they all enter together; keyed by map alone, rows that stay on the - page would swap in place without moving. */} -
    + ) : ( +
    +
    +

    + {q + ? `Maps matching “${q}”` + : tier != null + ? `Tier ${tier} maps` + : "All maps"} +

    +

    + {number.format(list.total)} maps in this view +

    +
    +
      + {list.maps.map((map, index) => ( +
    • - {list.maps.map((map, index) => ( -
    • - -
    • - ))} -
    - {list.total > PAGE_SIZE && ( -
    - href({ page: p })} - /> -
    - )} -
    - - )} -
+ + + ))} + + {list.total > PAGE_SIZE && ( +
+ href({ page: p })} + /> +
+ )} + + )}
); } @@ -422,19 +382,18 @@ function MapStats({ }) { const tiered = stats.by_tier.reduce((sum, count) => sum + count, 0); const hasTiers = stats.by_tier.length > 0; - if ( - !hasTiers && - stats.newest.length === 0 && - stats.played_this_week.length === 0 - ) + const newest = stats.newest.filter( + (map) => selected == null || map.tier === selected, + ); + const playedThisWeek = stats.played_this_week.filter( + (map) => selected == null || map.tier === selected, + ); + if (!hasTiers && newest.length === 0 && playedThisWeek.length === 0) return null; - // At full width (xl) the chart keeps the width it needs and the lists share what is left equally, each with a - // full-height divider. Narrower, that would cut map names to a few letters, so the chart takes its own row and the - // two lists sit side by side beneath it (stacked on a phone). return ( - + {hasTiers && ( -
+
)} - {stats.newest.length > 0 && ( + {newest.length > 0 && ( ({ + maps={newest.map((map) => ({ name: map.name, tier: map.tier, detail: formatSince(map.listed_at), @@ -455,10 +414,10 @@ function MapStats({ tierCount={tierCount} /> )} - {stats.played_this_week.length > 0 && ( + {playedThisWeek.length > 0 && ( ({ + maps={playedThisWeek.map((map) => ({ name: map.name, tier: map.tier, detail: `${number.format(map.players)} ${map.players === 1 ? "player" : "players"}`, @@ -483,7 +442,7 @@ function MapStatsList({ tierCount: number | null | undefined; }) { return ( -
+

{href ? ( @@ -493,7 +452,7 @@ function MapStatsList({ title )}

-
    +
      {maps.map((map) => (
    • )} - {map.name} + + {map.name} + {map.detail}
    • @@ -559,40 +520,52 @@ function MapRow({ return ( - - - - {map.tier != null && tierCount != null && ( - - )} - - {map.name} - - - - {map.players === 1 ? "1 player" : `${map.players} players`} - {map.bonuses > 0 && - ` · ${map.bonuses === 1 ? "1 bonus" : `${map.bonuses} bonuses`}`} - + + + {map.tier != null && tierCount != null && ( + + )} - {wr ? ( - - - {formatTime(wr.time)} + + + + {map.name} - - {wr.player.name} - {/* Most players have no country on Steam; a placeholder on every row would only be noise. */} - {wr.player.country_code && } + + {map.players === 1 ? "1 player" : `${map.players} players`} + {map.bonuses > 0 && + ` · ${map.bonuses === 1 ? "1 bonus" : `${map.bonuses} bonuses`}`} - ) : ( - - No record in this style + + + World record + + {wr ? ( + + + {formatTime(wr.time)} + + + {wr.player.name} + {wr.player.country_code && ( + + )} + + + ) : ( + + No record in this style + + )} - )} + ); } diff --git a/web/src/ui/SearchField.tsx b/web/src/ui/SearchField.tsx index 6503fe0..38e26fd 100644 --- a/web/src/ui/SearchField.tsx +++ b/web/src/ui/SearchField.tsx @@ -1,37 +1,74 @@ -// A search field with its button inside on the right, as the old sourcejump.net had it. Focus looks as the -// header search's does: the border turns accent and the field darkens, with no ring around it. Goes inside the -// caller's form, which does the searching. +"use client"; +// A search field that updates the current route after a short pause, so list pages do not need a submit button. +import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { Search } from "lucide-react"; +import { startTransition, useEffect, useState } from "react"; +import { classNames } from "./classNames"; export function SearchField({ name, defaultValue, placeholder, label, + className, + live = false, }: { name: string; defaultValue?: string; placeholder: string; /** Names the field for screen readers, since the placeholder isn't a label. */ label: string; + className?: string; + live?: boolean; }) { + const router = useRouter(); + const pathname = usePathname(); + const searchParams = useSearchParams(); + const [value, setValue] = useState(defaultValue ?? ""); + + useEffect(() => { + if (!live || value.trim() === (searchParams.get(name) ?? "")) return; + const timeout = window.setTimeout(() => { + const params = new URLSearchParams(searchParams.toString()); + const trimmed = value.trim(); + if (trimmed) params.set(name, trimmed); + else params.delete(name); + params.delete("page"); + const query = params.toString(); + const nextUrl = query ? `${pathname}?${query}` : pathname; + if (nextUrl !== window.location.pathname + window.location.search) { + startTransition(() => router.replace(nextUrl, { scroll: false })); + } + }, 350); + + return () => window.clearTimeout(timeout); + }, [live, name, pathname, router, searchParams, value]); + return ( -
      +
      setValue(event.target.value)} placeholder={placeholder} aria-label={label} - className="peer border-border bg-surface text-text placeholder:text-text-subtle hover:border-border-strong focus:border-accent focus:bg-bg h-10 w-full rounded-md border pr-11 pl-3.5 transition-colors duration-(--duration-fast) outline-none" + className="border-border bg-surface text-text placeholder:text-text-subtle hover:border-border-strong focus:border-accent focus:bg-bg h-9 w-full rounded-md border pr-10 pl-3.5 text-sm transition-colors duration-(--duration-fast) outline-none" /> - + {live ? ( + + ) : ( + + )}
      ); } diff --git a/web/src/ui/TierBadge.tsx b/web/src/ui/TierBadge.tsx index cf29c71..02cfba7 100644 --- a/web/src/ui/TierBadge.tsx +++ b/web/src/ui/TierBadge.tsx @@ -40,7 +40,7 @@ export function TierBadge({ // The width fits T1 to T9 alike and grows only for two digits; it never stretches to a grid column, where // one T10 would widen every badge beside it. Centered both ways, so the label sits in the middle of the box. className={classNames( - "inline-flex h-5 min-w-7 shrink-0 items-center justify-center self-center justify-self-start rounded-sm border border-(color:--tier) px-1 text-xs leading-none font-bold text-(color:--tier) tabular-nums", + "inline-flex h-5 min-w-7 shrink-0 items-center justify-center self-center justify-self-start rounded-sm bg-(--tier)/15 px-1 text-xs leading-none font-bold text-(color:--tier) tabular-nums", className, )} > diff --git a/web/src/ui/TierSpread.tsx b/web/src/ui/TierSpread.tsx index 42dc87b..b6e0716 100644 --- a/web/src/ui/TierSpread.tsx +++ b/web/src/ui/TierSpread.tsx @@ -1,284 +1,105 @@ -// How many maps hold each tier: a donut split by tier, each slice in its tier's color, beside each tier's count and -// share. Every slice and row links to the maps of that tier; the chosen tier stays bright and the others dim. -// Maps without a tier fill the donut's end in a neutral color. On a phone, where the donut and its list stood -// nearly a screen tall, it's a bar split by tier and the tiers as a grid of small tiles instead. +// Tier distribution and filters, with one responsive layout for every screen size. import type { CSSProperties } from "react"; import { classNames } from "./classNames"; import { Link } from "./Link"; import { TierBadge, tierColor } from "./TierBadge"; -/** Each tier's share of all maps, so the shares (with "No tier") add up to the whole list. */ -const percent = new Intl.NumberFormat("en", { - style: "percent", - maximumFractionDigits: 0, -}); const number = new Intl.NumberFormat("en"); -/** The ring's radius and width, in the SVG's 100-unit box. */ -const RADIUS = 40; -const WIDTH = 16; -/** Space between slices, in hundredths of the ring. */ -const GAP = 0.6; - -/** "All tiers", in the look of the page's filter menus and tier tiles: bordered, raised when it's the choice. */ -const allTiersClasses = (chosen: boolean) => - classNames( - "flex h-8 items-center gap-2 rounded-md border px-3 text-sm font-bold transition-colors duration-(--duration-fast)", - chosen - ? "bg-surface-raised border-border-strong text-text" - : "border-border text-text-muted hover:bg-text/4 hover:text-text", - ); - -const rowClasses = - "col-span-3 grid grid-cols-subgrid items-center rounded-md px-2.5 py-1 transition-[opacity,background-color] duration-(--duration-base)"; - -/** The chosen tier, filled and outlined in its own color (`--tier`), so it reads as the choice at a glance. */ -const chosenTier = "bg-(--tier)/15 ring-1 ring-(--tier)/50 ring-inset"; - export function TierSpread({ byTier, untiered, selected, tierHref, }: { - /** Maps per tier, tier 1 first; its length is the tier count. */ + /** Map counts in tier order, easiest first. */ byTier: number[]; + /** Maps which have no tier assigned. */ untiered: number; - /** The tier the list is filtered to, if any. */ + /** The selected tier, if the map list is filtered. */ selected?: number; - /** Where a tier leads; null for the whole list. */ + /** Where a tier tile should link. Null returns to the complete list. */ tierHref: (tier: number | null) => string; }) { const total = byTier.reduce((sum, count) => sum + count, untiered); if (total === 0) return null; const tierCount = byTier.length; - const dimmed = (tier: number) => selected != null && selected !== tier; - - // Each slice is a dashed stroke around the ring: as long as its share, starting where the last one ended. - // Strokes rather than wedge paths, so a slice is one circle and grows its width on hover. - const slices = byTier.map((count, index) => ({ - tier: index + 1, - count, - start: - (byTier.slice(0, index).reduce((sum, c) => sum + c, 0) / total) * 100, - length: (count / total) * 100, - })); - const tieredShare = (byTier.reduce((sum, c) => sum + c, 0) / total) * 100; - const chosen = selected != null ? byTier[selected - 1] : undefined; - const half = Math.ceil(tierCount / 2); - // The first column holds the lower half; the second the rest and "No tier" after them. - const rows = Math.max(half, tierCount - half + (untiered > 0 ? 1 : 0)); - const tierRow = ({ tier, count }: (typeof slices)[number]) => ( -
    • - - - {number.format(count)} - - {percent.format(count / total)} - - -
    • - ); - return ( - <> -
      - {/* The donut's shares laid end to end. */} -
      +
      +

      Difficulty

      + - {slices.map( - ({ tier, count }) => - count > 0 && ( - - ), - )} - {untiered > 0 && } -
      -
      - - All tiers - - {number.format(total - untiered)} maps - - - {untiered > 0 && ( - - {number.format(untiered)} without a tier - - )} -
      -
        - {slices.map(({ tier, count }) => ( -
      • + All tiers{" "} + {number.format(total)} + +
      +
      + {byTier.map( + (count, index) => + count > 0 && ( + + ), + )} + {untiered > 0 && } +
      +
        + {byTier.map((count, index) => { + const tier = index + 1; + const active = selected === tier; + return ( +
      • - - + + {number.format(count)}
      • - ))} -
      -
      -
      - - {untiered > 0 && ( - - )} - {slices.map( - ({ tier, count, start, length }) => - count > 0 && ( - - {`Tier ${tier}: ${number.format(count)} maps`} - - - ), - )} - {/* Counter-rotated, so the middle reads upright inside the turned ring. */} - - - {selected != null ? `T${selected}` : "All"} - - {chosen != null && ( - - {number.format(chosen)} maps - - )} - - - - {/* "All tiers", always there to go back to, centered over the two columns it sums; the tiers split evenly - below it, low tiers first, and "No tier" ends the second column. */} -
      - - All tiers - - {number.format(total - untiered)} maps - - -
        - {slices.slice(0, half).map(tierRow)} - {slices.slice(half).map(tierRow)} - {untiered > 0 && ( -
      • - No tier - - {number.format(untiered)} - - - {percent.format(untiered / total)} - -
      • - )} -
      -
      -
      - + ); + })} +
    + {untiered > 0 && ( +

    + {number.format(untiered)} without a tier +

    + )} +
); }