diff --git a/api/.sqlx/query-d26414df0abf398bda09dccdafcd315b7ba5f4c8c40779dde663ee8272e27ebe.json b/api/.sqlx/query-4c09e53a43e1c3f9862537c21606c89f29db1377e6bb0e0449f2e4fe91912fcf.json similarity index 75% rename from api/.sqlx/query-d26414df0abf398bda09dccdafcd315b7ba5f4c8c40779dde663ee8272e27ebe.json rename to api/.sqlx/query-4c09e53a43e1c3f9862537c21606c89f29db1377e6bb0e0449f2e4fe91912fcf.json index eedb98e..94cb7c5 100644 --- a/api/.sqlx/query-d26414df0abf398bda09dccdafcd315b7ba5f4c8c40779dde663ee8272e27ebe.json +++ b/api/.sqlx/query-4c09e53a43e1c3f9862537c21606c89f29db1377e6bb0e0449f2e4fe91912fcf.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT m.name, week.players AS \"players!\",\n (SELECT tier FROM current_map_tiers WHERE map_id = m.id AND track = 0) AS tier\n FROM (SELECT map_id, count(DISTINCT player_steamid64) AS players FROM runs\n WHERE invalidated_at IS NULL AND finished_at > now() - interval '7 days'\n GROUP BY map_id) week\n JOIN maps m ON m.id = week.map_id\n ORDER BY week.players DESC, m.name LIMIT $1", + "query": "SELECT m.name, week.players AS \"players!\",\n (SELECT tier FROM current_map_tiers WHERE map_id = m.id AND track = 0) AS tier\n FROM (SELECT map_id, count(DISTINCT player_steamid64) AS players FROM runs\n WHERE invalidated_at IS NULL AND finished_at > now() - interval '7 days'\n GROUP BY map_id) week\n JOIN maps m ON m.id = week.map_id\n WHERE $2::smallint IS NULL OR $2 =\n (SELECT tier FROM current_map_tiers WHERE map_id = m.id AND track = 0)\n ORDER BY week.players DESC, m.name LIMIT $1", "describe": { "columns": [ { @@ -29,7 +29,8 @@ ], "parameters": { "Left": [ - "Int8" + "Int8", + "Int2" ] }, "nullable": [ @@ -38,5 +39,5 @@ null ] }, - "hash": "d26414df0abf398bda09dccdafcd315b7ba5f4c8c40779dde663ee8272e27ebe" + "hash": "4c09e53a43e1c3f9862537c21606c89f29db1377e6bb0e0449f2e4fe91912fcf" } diff --git a/api/.sqlx/query-01f7dd297b27ffd70d058c7c02094146e2c7bc8d6c35edad46bb4a32514d6caf.json b/api/.sqlx/query-8e5923b7bc514b6f049477cb1bb1592b470e280661f42180c0ea57f6a36d2fa3.json similarity index 72% rename from api/.sqlx/query-01f7dd297b27ffd70d058c7c02094146e2c7bc8d6c35edad46bb4a32514d6caf.json rename to api/.sqlx/query-8e5923b7bc514b6f049477cb1bb1592b470e280661f42180c0ea57f6a36d2fa3.json index 8186b14..859f51a 100644 --- a/api/.sqlx/query-01f7dd297b27ffd70d058c7c02094146e2c7bc8d6c35edad46bb4a32514d6caf.json +++ b/api/.sqlx/query-8e5923b7bc514b6f049477cb1bb1592b470e280661f42180c0ea57f6a36d2fa3.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT m.name, m.listed_at AS \"listed_at!\",\n (SELECT tier FROM current_map_tiers WHERE map_id = m.id AND track = 0) AS tier\n FROM maps m WHERE m.last_run_at IS NOT NULL AND m.listed_at IS NOT NULL\n ORDER BY m.listed_at DESC, m.name LIMIT $1", + "query": "SELECT m.name, m.listed_at AS \"listed_at!\",\n (SELECT tier FROM current_map_tiers WHERE map_id = m.id AND track = 0) AS tier\n FROM maps m WHERE m.last_run_at IS NOT NULL AND m.listed_at IS NOT NULL\n AND ($2::smallint IS NULL OR $2 =\n (SELECT tier FROM current_map_tiers WHERE map_id = m.id AND track = 0))\n ORDER BY m.listed_at DESC, m.name LIMIT $1", "describe": { "columns": [ { @@ -34,7 +34,8 @@ ], "parameters": { "Left": [ - "Int8" + "Int8", + "Int2" ] }, "nullable": [ @@ -43,5 +44,5 @@ null ] }, - "hash": "01f7dd297b27ffd70d058c7c02094146e2c7bc8d6c35edad46bb4a32514d6caf" + "hash": "8e5923b7bc514b6f049477cb1bb1592b470e280661f42180c0ea57f6a36d2fa3" } diff --git a/api/crates/api/src/maps/list.rs b/api/crates/api/src/maps/list.rs index 601869b..830d02d 100644 --- a/api/crates/api/src/maps/list.rs +++ b/api/crates/api/src/maps/list.rs @@ -114,7 +114,7 @@ pub struct MapList { pub stats: MapStats, } -/// The whole list at a glance, whatever the search or filter. +/// Global totals and tier-scoped newest and weekly lists. #[derive(Debug, Serialize, Deserialize, ToSchema)] pub struct MapStats { /// Maps with at least one run. @@ -122,6 +122,8 @@ pub struct MapStats { /// Of those, the maps whose main track has each tier, tier 1 first. Empty until a tier count is /// published. pub by_tier: Vec, + /// The tier the newest and weekly lists describe; None describes all tiers. Totals remain global. + pub tier: Option, /// The maps that joined the list last, newest first. pub newest: Vec, /// The maps the most players finished a run on in the last 7 days, most first. @@ -218,7 +220,7 @@ pub async fn list_maps( tx.commit().await?; let tier_count = tiers::tier_count(&state.db).await?; - let list_stats = map_stats(&state.db, tier_count).await?; + let list_stats = map_stats(&state.db, tier_count, query.tier).await?; let (player, completed) = match player { Some(player) => ( known_player(&state.db, player).await?, @@ -244,7 +246,11 @@ pub async fn list_maps( /// Maps with a run, how many hold each main-track tier once tiers are in force, the newest of them and the /// week's most played. -async fn map_stats(db: &sqlx::PgPool, tier_count: Option) -> Result { +async fn map_stats( + db: &sqlx::PgPool, + tier_count: Option, + tier: Option, +) -> Result { let rows = sqlx::query!( r#"SELECT tier.tier AS "tier?", count(*) AS "maps!" FROM maps m LEFT JOIN current_map_tiers tier ON tier.map_id = m.id AND tier.track = 0 @@ -267,8 +273,11 @@ async fn map_stats(db: &sqlx::PgPool, tier_count: Option) -> Result) -> Result now() - interval '7 days' GROUP BY map_id) week JOIN maps m ON m.id = week.map_id + WHERE $2::smallint IS NULL OR $2 = + (SELECT tier FROM current_map_tiers WHERE map_id = m.id AND track = 0) ORDER BY week.players DESC, m.name LIMIT $1"#, - PLAYED_THIS_WEEK + PLAYED_THIS_WEEK, + tier ) .fetch_all(db) .await? @@ -303,6 +315,7 @@ async fn map_stats(db: &sqlx::PgPool, tier_count: Option) -> Result = (5..10) + .map(|index| format!("bhop_tier_{index:02}")) + .collect(); + assert_eq!(filtered.stats.tier, Some(2)); + assert_eq!( + (filtered.stats.maps, filtered.stats.by_tier), + (12, vec![5, 7]) + ); + assert_eq!(filtered.stats.played_this_week.len(), 5); + assert_eq!(filtered.stats.newest.len(), 5); + for (index, map) in filtered.stats.played_this_week.iter().enumerate() { + assert_eq!(map.name, expected[index]); + assert_eq!((map.tier, map.players), (Some(2), 1)); + } + for (index, map) in filtered.stats.newest.iter().enumerate() { + assert_eq!(map.name, expected[index]); + assert_eq!(map.tier, Some(2)); + } + } + #[sqlx::test] async fn sorts_by_record_and_filters_by_completion(db: PgPool) { let key = setup(&db).await; diff --git a/api/openapi.json b/api/openapi.json index b7641cf..ff67698 100644 --- a/api/openapi.json +++ b/api/openapi.json @@ -7862,7 +7862,7 @@ }, "MapStats": { "type": "object", - "description": "The whole list at a glance, whatever the search or filter.", + "description": "Global totals and tier-scoped newest and weekly lists.", "required": [ "maps", "by_tier", @@ -7896,6 +7896,14 @@ "$ref": "#/components/schemas/PlayedMap" }, "description": "The maps the most players finished a run on in the last 7 days, most first." + }, + "tier": { + "type": [ + "integer", + "null" + ], + "format": "int32", + "description": "The tier the newest and weekly lists describe; None describes all tiers. Totals remain global." } } }, diff --git a/docs/design-system.md b/docs/design-system.md index 866f571..5b36de7 100644 --- a/docs/design-system.md +++ b/docs/design-system.md @@ -3,7 +3,7 @@ One visual language for every page, so pages can't drift apart. See it at `/dev/ ## Direction "Classic" (2026-11-07): the old sourcejump.net, updated. Replaced "Navy". -- A slate sheet (`bg`, `shadow-sheet`) between darker gutters. One cyan accent; at most one primary button per view. +- A slate sheet (`bg`, `shadow-sheet`) with gutters, halfway from 72rem to full width. One cyan accent; at most one primary button per view. - Gamified but professional: medals, tier colors, WR badges, count-ups and small motions. No mascots, confetti, slogans or sales copy. - Geist: 450 regular, 700 bold, matched to the old Play; Exo 2 bold (`font-server`) for server names. Times and tables use equal-width digits. - Corners: `rounded-md` (8px) for every frame, from a panel to a field or button; `rounded-sm` (4px) for badges and rows inside a frame. @@ -41,7 +41,7 @@ One visual language for every page, so pages can't drift apart. See it at `/dev/ | `DividedList`, `DividedSection` | Rows with lines between them, and a part set off by a line above, inside a `Card` or `Dialog`. The lines run to the surface's edges | | `StepChart` | A value that changes in steps over time (WR history). Hover snaps a crosshair to the nearest point; points take focus and open their link | | `LineChart` | One count over time from zero (players online). CSS-stretched, so it fills its box before scripts load. Hover, tap or arrow keys pick a point; the parent shows its values. An optional second line (`y2`, gold) shows a part of the first on the same scale (world records among runs). Never two scales on one chart | -| `TierSpread` | Maps per tier: a donut beside each tier's count and share; slices and rows link to that tier's maps, the rest dim; "All tiers" goes back (Maps page) | +| `TierSpread` | Tier donut (bar on phones) and count/share legend. Rows and slices filter maps; "All tiers" resets; other slices dim | | `Dot` | "·" in a wrapping line; hidden on phones, where it could end one | | `Tooltip` | Hint on hover and focus; child takes focus | | `Menu`, `MenuItem`, `MenuLink`, `MenuSeparator` | Menu button (account; `sheet`: phone menu) | diff --git a/docs/site-api.md b/docs/site-api.md index e690e50..fd522f8 100644 --- a/docs/site-api.md +++ b/docs/site-api.md @@ -19,7 +19,7 @@ Players sign in with Steam (OpenID 2.0); the endpoints answer browsers (redirect - Staff privileges: a bitmap in `players.privileges` (`players/privileges.rs`); bit positions never change; the API names them, never numbers. `players.restrictions` is unused (bans hold restrictions). The CLI's `privileges grant …`, `revoke`, `list` and the staff tools share `staff/privileges.rs`. ## Maps and leaderboards -- The map list holds every map with a run (`maps.last_run_at`, set by the ingest); whether one is ranked is open. Sorts: name, players, last/first run (`listed_at`), tier, main-track record; `tier` keeps one tier. `player` (any SteamID form) with `completed=true|false` keeps maps whose main track they have or haven't finished in the list's style; `completed` counts them. `stats`: tiers, 5 newest, 5 most players this week. +- Maps with runs (`maps.last_run_at`, set on ingest); ranking is open. Sorts: name, players, last/first run (`listed_at`), tier and main-track WR. `tier` keeps one main tier. `player` (any SteamID) with `completed=true|false` filters the style's main-track completions; `completed` counts them. `stats` totals stay global; newest and weekly lists take five within `stats.tier` (null: all). Weekly ranks count distinct players. - Leaderboards rank PBs per map, style and track; equal times share a place, the earlier run listed first. A tie's world record belongs to whoever set it first. - `GET /v1/maps/{map}` carries every style and track's top 25, `next_cursor` and WR history, for map pages to switch locally. `…/leaderboard?cursor=` pages on from there; cursors are opaque. - WR history: every run faster than all finished before it on that board, by `finished_at`; ties don't count. diff --git a/web/e2e/maps-cards.e2e.ts b/web/e2e/maps-cards.e2e.ts new file mode 100644 index 0000000..a4171c7 --- /dev/null +++ b/web/e2e/maps-cards.e2e.ts @@ -0,0 +1,173 @@ +// Map-card regressions: real podiums, complete text, responsive columns and stable image dimensions. +import { expect, test, type Locator } from "@playwright/test"; +import type { Schemas } from "../src/api/client"; +import { formatTime } from "../src/features/runs/time"; + +async function expectTextInside(card: Locator) { + const clipped = await card.evaluate((element) => { + const bounds = element.getBoundingClientRect(); + const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT); + const failures: string[] = []; + let node; + while ((node = walker.nextNode())) { + if (!node.textContent?.trim()) continue; + const range = document.createRange(); + range.selectNodeContents(node); + for (const rect of Array.from(range.getClientRects())) { + if ( + rect.left < bounds.left - 1 || + rect.right > bounds.right + 1 || + rect.top < bounds.top - 1 || + rect.bottom > bounds.bottom + 1 + ) { + failures.push(node.textContent); + } + } + } + return failures; + }); + expect(clipped).toEqual([]); +} + +test("cards show the API's top three for the chosen style", async ({ + page, + request, +}) => { + const response = await request.get("/v1/maps?limit=1&sort=popular"); + const list = (await response.json()) as Schemas["MapList"]; + const map = list.maps[0]!; + const result = await request.get( + `/v1/maps/${encodeURIComponent(map.name)}/leaderboard?style=${list.style}&limit=3`, + ); + const board = (await result.json()) as Schemas["Leaderboard"]; + await page.goto("/maps"); + const card = page.locator(`[data-map="${map.name}"]`); + await expect(card).toBeVisible(); + const rows = card.locator("ol > li"); + await expect(rows).toHaveCount(board.entries.length); + for (let index = 0; index < board.entries.length; index++) { + const entry = board.entries[index]!; + await expect( + rows.nth(index).getByLabel(`Placement ${entry.rank}`), + ).toBeVisible(); + await expect( + rows.nth(index).getByText(entry.player.name, { exact: true }), + ).toBeVisible(); + await expect( + rows.nth(index).getByText(formatTime(entry.time), { exact: true }), + ).toBeVisible(); + } + await expectTextInside(card); +}); + +test("cards keep complete names and long times inside at every breakpoint", async ({ + page, +}) => { + await page.goto("/maps"); + const card = page.locator("[data-map]").first(); + await expect(card).toBeVisible(); + await page.evaluate(() => document.fonts.ready); + await card.evaluate((element) => { + element.querySelector("h3")!.textContent = + "bhop_" + "long_map_name_".repeat(5).slice(0, 59); + for (const row of Array.from(element.querySelectorAll("ol > li"))) { + const player = row.children[2]!; + const result = row.children[3]!; + player.textContent = "Long player name 玩家 日本語 Кириллица"; + result.children[0]!.textContent = "1:23:45.678"; + result.children[1]!.textContent = "+2:34:56.789"; + } + }); + for (const width of [1440, 1084, 1080, 1024, 768, 390, 320]) { + await page.setViewportSize({ width, height: 1000 }); + await expectTextInside(card); + expect( + await page.evaluate( + () => document.documentElement.scrollWidth > innerWidth, + ), + ).toBe(false); + const layout = await card.evaluate((element) => ({ + width: element.clientWidth, + result: getComputedStyle( + element.querySelector("ol > li > span:last-child")!, + ).display, + })); + expect(layout.result).toBe(layout.width >= 320 ? "grid" : "flex"); + } +}); + +test("loading avatars and map pictures does not move the podium", async ({ + page, +}) => { + await page.route(/avatars\.(?:akamai\.)?steamstatic\.com/, (route) => + route.abort(), + ); + await page.goto("/maps"); + const card = page.locator("[data-map]").first(); + await expect(card).toBeVisible(); + await page.evaluate(() => document.fonts.ready); + const before = await card.locator("ol").boundingBox(); + await card + .locator("img") + .evaluateAll((images) => + Promise.all( + images.map((image) => + (image as HTMLImageElement).decode().catch(() => {}), + ), + ), + ); + expect(await card.locator("ol").boundingBox()).toEqual(before); + await expect(card.locator("ol img")).toHaveCount(0); + await expectTextInside(card); +}); + +test("a single finisher and an empty style stay honest and readable", async ({ + page, + request, +}) => { + const response = await request.get("/v1/maps?style=scroll&limit=100"); + const list = (await response.json()) as Schemas["MapList"]; + test.skip(list.style !== "scroll", "The API has no Scroll style."); + const empty = list.maps.find((map) => !map.world_record); + test.skip(!empty, "The current API data has no empty Scroll board."); + await page.setViewportSize({ width: 390, height: 900 }); + await page.goto(`/maps?style=scroll&q=${encodeURIComponent(empty!.name)}`); + const emptyCard = page.locator(`[data-map="${empty!.name}"]`); + await expect( + emptyCard.getByText("No times in this style", { exact: true }), + ).toBeVisible(); + await expect(emptyCard.getByLabel("Placement 1")).toHaveCount(0); + await expectTextInside(emptyCard); + await expect(emptyCard).toHaveAttribute( + "href", + `/maps/${empty!.name}?style=scroll`, + ); + + // Pick an actual sparse board rather than inventing second and third place. + let single: string | undefined; + for (const map of list.maps + .filter((map) => map.world_record) + .sort((a, b) => a.players - b.players) + .slice(0, 6)) { + const response = await request.get( + `/v1/maps/${encodeURIComponent(map.name)}/leaderboard?style=scroll&limit=3`, + ); + const board = (await response.json()) as Schemas["Leaderboard"]; + if (board.total === 1) { + single = map.name; + break; + } + } + test.skip( + !single, + "The current API data has no sampled Scroll board with one finisher.", + ); + await page.goto(`/maps?style=scroll&q=${encodeURIComponent(single!)}`); + const singleCard = page.locator(`[data-map="${single}"]`); + await expect( + singleCard.getByText("1 ranked time in this style", { exact: true }), + ).toBeVisible(); + await expect(singleCard.getByLabel("Placement 1")).toBeVisible(); + await expect(singleCard.getByLabel("Placement 2")).toHaveCount(0); + await expectTextInside(singleCard); +}); diff --git a/web/e2e/maps-overview.e2e.ts b/web/e2e/maps-overview.e2e.ts new file mode 100644 index 0000000..1084cf4 --- /dev/null +++ b/web/e2e/maps-overview.e2e.ts @@ -0,0 +1,180 @@ +// Regression checks for the Maps overview's alignment and filtered layouts. +import { expect, test, type Locator } from "@playwright/test"; +import type { Schemas } from "../src/api/client"; + +async function expectAligned(overview: Locator) { + const geometry = await overview.evaluate((element) => { + const nav = element.querySelector("nav")!; + const links = nav.querySelectorAll("li a"); + const reset = nav.querySelector("a")!.getBoundingClientRect(); + const first = links[0]!.firstElementChild!.getBoundingClientRect(); + const last = + links[links.length - 1]!.lastElementChild!.getBoundingClientRect(); + const panel = element.getBoundingClientRect(); + const graph = element.querySelector("svg")!.getBoundingClientRect(); + const legend = nav.getBoundingClientRect(); + const center = (rect: DOMRect) => rect.y + rect.height / 2; + return { + left: Math.abs(reset.left - first.left), + right: Math.abs(reset.right - last.right), + graph: Math.abs(center(graph) - center(panel)), + legend: Math.abs(center(legend) - center(panel)), + headings: Array.from(element.querySelectorAll("section h2")).map( + (heading) => heading.getBoundingClientRect().top, + ), + lists: Array.from(element.querySelectorAll("section > div")).map( + (group) => + Math.abs(center(group.getBoundingClientRect()) - center(panel)), + ), + }; + }); + expect(geometry.left).toBeLessThan(1); + expect(geometry.right).toBeLessThan(1); + expect(geometry.graph).toBeLessThan(1); + expect(geometry.legend).toBeLessThan(1); + for (const offset of geometry.lists) expect(offset).toBeLessThan(1); + for (const top of geometry.headings) { + expect(Math.abs(top - geometry.headings[0]!)).toBeLessThan(1); + } +} + +test("the overview stays centered and the reset matches the tier columns", async ({ + page, +}) => { + await page.goto("/maps"); + const overview = page.getByRole("region", { + name: "Map overview", + exact: true, + }); + const nav = overview.getByRole("navigation", { name: "Filter maps by tier" }); + await expect(nav).toBeVisible(); + await page.evaluate(() => document.fonts.ready); + await expectAligned(overview); + + // The page name remains available to screen readers without adding a visible heading. + const heading = await page + .getByRole("heading", { name: "Maps", exact: true }) + .boundingBox(); + expect(heading!.height).toBeLessThanOrEqual(1); + + const reset = nav.getByRole("link", { name: /All tiers/ }); + const firstTier = nav.locator("li a").first(); + const bounds = await firstTier.boundingBox(); + await firstTier.hover(); + expect(await firstTier.boundingBox()).toEqual(bounds); + await reset.focus(); + await page.keyboard.press("Tab"); + await expect(firstTier).toBeFocused(); + await page.keyboard.press("Enter"); + await expect(firstTier).toHaveAttribute("aria-current", "true"); + await expectAligned(overview); + await reset.click(); + await expect(reset).toHaveAttribute("aria-current", "true"); + await expectAligned(overview); +}); + +test("a filtered short list is centered and its details stay beside the names", async ({ + page, + request, +}) => { + const response = await request.get("/v1/maps?limit=1"); + expect(response.ok()).toBe(true); + const { stats } = (await response.json()) as { stats: Schemas["MapStats"] }; + const tier = + stats.by_tier.findIndex((_, index) => { + const newest = stats.newest.filter( + (map) => map.tier === index + 1, + ).length; + const played = stats.played_this_week.filter( + (map) => map.tier === index + 1, + ).length; + return ( + (newest > 0 && newest < 5 && played === 0) || + (played > 0 && played < 5 && newest === 0) + ); + }) + 1; + test.skip( + tier === 0, + "The current API data has no tier with just one short summary list.", + ); + + await page.goto("/maps"); + const headingPositions = await page + .getByRole("region", { name: "Map overview", exact: true }) + .locator("section") + .evaluateAll((sections) => + Object.fromEntries( + sections.map((section) => [ + section.getAttribute("aria-label"), + section.querySelector("h2")!.getBoundingClientRect().top, + ]), + ), + ); + + await page.goto(`/maps?tier=${tier}`); + const overview = page.getByRole("region", { + name: "Map overview", + exact: true, + }); + await expect(overview.getByRole("navigation")).toBeVisible(); + await page.evaluate(() => document.fonts.ready); + await expectAligned(overview); + const filteredHeading = await overview + .locator("section:has(ul)") + .first() + .evaluate((section) => ({ + name: section.getAttribute("aria-label")!, + top: section.querySelector("h2")!.getBoundingClientRect().top, + })); + expect( + Math.abs(filteredHeading.top - headingPositions[filteredHeading.name]), + ).toBeLessThan(1); + const list = overview.locator("section:has(ul)").first().locator("ul"); + await expect(list).toHaveCount(1); + const layout = await list.evaluate((element) => { + const rows = Array.from(element.querySelectorAll("a")); + return { + width: element.getBoundingClientRect().width, + details: rows.map( + (row) => row.lastElementChild!.getBoundingClientRect().left, + ), + gaps: rows.map((row) => { + const name = row.children[1]!; + const detail = row.children[2]!; + return ( + detail.getBoundingClientRect().left - + name.getBoundingClientRect().right + ); + }), + }; + }); + expect(layout.width).toBeLessThan(400); + for (const left of layout.details) + expect(Math.abs(left - layout.details[0]!)).toBeLessThan(1); + for (const gap of layout.gaps) expect(gap).toBe(8); +}); + +test("the compact legend fits a narrow phone without changing its reset alignment", async ({ + page, +}) => { + await page.setViewportSize({ width: 320, height: 900 }); + await page.goto("/maps"); + const nav = page.getByRole("navigation", { name: "Filter maps by tier" }); + await expect(nav).toBeVisible(); + const edges = await nav.evaluate((element) => { + const reset = element.querySelector("a")!.getBoundingClientRect(); + const links = element.querySelectorAll("li a"); + return { + left: + reset.left - links[0]!.firstElementChild!.getBoundingClientRect().left, + right: + reset.right - + links[links.length - 1]!.lastElementChild!.getBoundingClientRect() + .right, + overflow: document.documentElement.scrollWidth > innerWidth, + }; + }); + expect(Math.abs(edges.left)).toBeLessThan(1); + expect(Math.abs(edges.right)).toBeLessThan(1); + expect(edges.overflow).toBe(false); +}); diff --git a/web/e2e/style-guide.e2e.ts-snapshots/desktop-chrome-linux.png b/web/e2e/style-guide.e2e.ts-snapshots/desktop-chrome-linux.png index a5a97a4..a395a37 100644 Binary files a/web/e2e/style-guide.e2e.ts-snapshots/desktop-chrome-linux.png and b/web/e2e/style-guide.e2e.ts-snapshots/desktop-chrome-linux.png differ diff --git a/web/e2e/style-guide.e2e.ts-snapshots/dialog-chrome-linux.png b/web/e2e/style-guide.e2e.ts-snapshots/dialog-chrome-linux.png index da59c31..f88f6c4 100644 Binary files a/web/e2e/style-guide.e2e.ts-snapshots/dialog-chrome-linux.png and b/web/e2e/style-guide.e2e.ts-snapshots/dialog-chrome-linux.png differ diff --git a/web/e2e/style-guide.e2e.ts-snapshots/menu-chrome-linux.png b/web/e2e/style-guide.e2e.ts-snapshots/menu-chrome-linux.png index 20dde9a..5e728d7 100644 Binary files a/web/e2e/style-guide.e2e.ts-snapshots/menu-chrome-linux.png and b/web/e2e/style-guide.e2e.ts-snapshots/menu-chrome-linux.png differ diff --git a/web/e2e/style-guide.e2e.ts-snapshots/phone-chrome-linux.png b/web/e2e/style-guide.e2e.ts-snapshots/phone-chrome-linux.png index e7e25be..17c8df7 100644 Binary files a/web/e2e/style-guide.e2e.ts-snapshots/phone-chrome-linux.png and b/web/e2e/style-guide.e2e.ts-snapshots/phone-chrome-linux.png differ diff --git a/web/next.config.ts b/web/next.config.ts index bbe0a26..4ca998d 100644 --- a/web/next.config.ts +++ b/web/next.config.ts @@ -29,6 +29,8 @@ const nextConfig: NextConfig = { turbopack: { rules: { "*.css": { + // CSS Modules use Next's native pipeline; rewriting their extension would lose the class exports. + condition: { not: { path: "*.module.css" } }, loaders: ["@tailwindcss/turbopack"], as: "*.css", }, diff --git a/web/src/api/schema.ts b/web/src/api/schema.ts index 12fbab9..81060d7 100644 --- a/web/src/api/schema.ts +++ b/web/src/api/schema.ts @@ -2218,7 +2218,7 @@ export interface components { /** @description Sorted by style, track and rank. One flat list keeps it simple to read in SourcePawn. */ records: components["schemas"]["Record"][]; }; - /** @description The whole list at a glance, whatever the search or filter. */ + /** @description Global totals and tier-scoped newest and weekly lists. */ MapStats: { /** * @description Of those, the maps whose main track has each tier, tier 1 first. Empty until a tier count is @@ -2234,6 +2234,11 @@ export interface components { newest: components["schemas"]["NewestMap"][]; /** @description The maps the most players finished a run on in the last 7 days, most first. */ played_this_week: components["schemas"]["PlayedMap"][]; + /** + * Format: int32 + * @description The tier the newest and weekly lists describe; None describes all tiers. Totals remain global. + */ + tier?: number | null; }; MapStyle: { /** @description The top of the leaderboard, so a map page can switch styles and tracks without asking again. */ diff --git a/web/src/app/layout.tsx b/web/src/app/layout.tsx index 25cf7a7..71fcdae 100644 --- a/web/src/app/layout.tsx +++ b/web/src/app/layout.tsx @@ -56,7 +56,7 @@ export default function RootLayout({ children }: LayoutProps<"/">) { {/* The sheet, as the old sourcejump.net had it: one column down the middle of the window, edges lit, holding the header, the page and the footer, the gutters either side. */} -
+
{/* The header and page fill at least the window, so the footer starts right at the fold: the page always scrolls, and the scrollbar doesn't come and go between short and long pages. The space above the footer is padding in here, not a margin on the footer, so it doesn't push it lower. */} diff --git a/web/src/app/maps/page.tsx b/web/src/app/maps/page.tsx index 3fe560d..8f37dcc 100644 --- a/web/src/app/maps/page.tsx +++ b/web/src/app/maps/page.tsx @@ -1,5 +1,4 @@ -// Maps page: every map with a finished run, searchable, with its world record in a chosen style. MapList sets out -// the page, title included, since the count beside the title comes with the list. +// Maps page: the difficulty overview, filters and maps with a finished run in the chosen style. import type { Metadata } from "next"; import { MapList } from "@/features/maps/MapList"; import { Page } from "@/ui/Page"; diff --git a/web/src/app/players/[steamid]/layout.tsx b/web/src/app/players/[steamid]/layout.tsx index 9df8188..e90354d 100644 --- a/web/src/app/players/[steamid]/layout.tsx +++ b/web/src/app/players/[steamid]/layout.tsx @@ -12,7 +12,7 @@ export default function PlayerLayout({ {params.then(({ steamid }) => ( ))} -
+
{children}
diff --git a/web/src/app/staff/layout.tsx b/web/src/app/staff/layout.tsx index 3533bcd..be9e8ad 100644 --- a/web/src/app/staff/layout.tsx +++ b/web/src/app/staff/layout.tsx @@ -9,7 +9,7 @@ export const metadata: Metadata = { export default function StaffLayout({ children }: LayoutProps<"/staff">) { return ( -
+
{children}
diff --git a/web/src/features/maps/MapCard.module.css b/web/src/features/maps/MapCard.module.css new file mode 100644 index 0000000..f42f68f --- /dev/null +++ b/web/src/features/maps/MapCard.module.css @@ -0,0 +1,89 @@ +/* Shared podium columns switch with the card's width, not the viewport's. */ +.picture { + mask-image: linear-gradient(to right, black 40%, transparent 60%); +} + +.cards { + grid-template-columns: minmax(0, 1fr); +} + +.podium { + align-content: start; + grid-template-columns: auto auto minmax(0, 1fr); + min-block-size: calc(var(--spacing) * 38); +} + +.entry { + min-block-size: calc(var(--spacing) * 12); + grid-column: 1 / -1; + grid-template-columns: subgrid; +} + +.rank { + grid-column: 1; + grid-row: 1 / span 2; +} + +.avatar { + grid-column: 2; + grid-row: 1 / span 2; +} + +.player { + grid-column: 3; + grid-row: 1; +} + +.result { + grid-column: 3; + grid-row: 2; +} + +/* Intrinsic name and time columns stay together instead of filling the card with blank space. */ +@container (min-width: 20rem) { + .podium { + grid-template-columns: + auto auto minmax(0, max-content) + max-content max-content; + min-block-size: calc(var(--spacing) * 26); + } + + .entry { + min-block-size: calc(var(--spacing) * 8); + } + + .player, + .result { + align-self: center; + } + + .rank, + .avatar { + grid-row: 1; + } + + .result { + display: grid; + grid-column: 4 / span 2; + grid-row: 1; + grid-template-columns: subgrid; + } +} + +@container (min-width: 42rem) { + .cards { + grid-template-columns: repeat(2, minmax(0, 1fr)); + } +} + +@container (min-width: 64rem) { + .cards { + grid-template-columns: repeat(3, minmax(0, 1fr)); + } +} + +@container (min-width: 88rem) { + .cards { + grid-template-columns: repeat(4, minmax(0, 1fr)); + } +} diff --git a/web/src/features/maps/MapCard.tsx b/web/src/features/maps/MapCard.tsx new file mode 100644 index 0000000..2196dec --- /dev/null +++ b/web/src/features/maps/MapCard.tsx @@ -0,0 +1,149 @@ +// A map preview with its main-track top three; names wrap and numeric columns stay aligned. +import type { Schemas } from "@/api/client"; +import { avatarSrc } from "@/features/players/avatarSrc"; +import { formatGap, formatTime } from "@/features/runs/time"; +import { Avatar } from "@/ui/Avatar"; +import { Badge } from "@/ui/Badge"; +import { classNames } from "@/ui/classNames"; +import { Link } from "@/ui/Link"; +import { Medal } from "@/ui/Medal"; +import { TierBadge } from "@/ui/TierBadge"; +import { MapImage } from "./MapImage"; +import type { MapLeader } from "./mapPodiums"; +import styles from "./MapCard.module.css"; + +const number = new Intl.NumberFormat("en"); + +export function MapCard({ + map, + tierCount, + leaders, + styleName, + styleKey, +}: { + map: Schemas["MapSummary"]; + tierCount: number | null | undefined; + leaders: readonly MapLeader[] | null; + styleName: string; + styleKey?: string; +}) { + const entries = + leaders ?? (map.world_record ? [{ ...map.world_record, rank: 1 }] : []); + const record = entries[0]; + const fastest = record?.time ?? 0; + + return ( + +
+ +
+
+
+ {map.tier != null && tierCount != null && ( + + + + )} +

+ {map.name} +

+
+

+ + {number.format(map.players)}{" "} + {map.players === 1 ? "player" : "players"} + + {map.bonuses > 0 && ( + + {number.format(map.bonuses)}{" "} + {map.bonuses === 1 ? "bonus" : "bonuses"} + + )} +

+
+
+
    + {entries.map((entry) => ( +
  1. + + + + + + + + {entry.player.name} + + + + {formatTime(entry.time)} + + {entry.run_id === record?.run_id ? ( + + WR + + ) : ( + + {formatGap(entry.time - fastest)} + + )} + +
  2. + ))} + {entries.length === 0 && ( +
  3. + No times in this style +
  4. + )} + {entries.length > 0 && entries.length < 3 && ( +
  5. + {leaders == null + ? "Top 3 couldn't be loaded" + : `${entries.length} ${entries.length === 1 ? "ranked time" : "ranked times"} in this style`} +
  6. + )} +
+
+ + ); +} diff --git a/web/src/features/maps/MapImage.tsx b/web/src/features/maps/MapImage.tsx index ba8745f..33cf84d 100644 --- a/web/src/features/maps/MapImage.tsx +++ b/web/src/features/maps/MapImage.tsx @@ -8,7 +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", + card: "h-full w-full rounded-none border-0", banner: "h-36 w-full rounded-md lg:h-44", }; @@ -51,7 +51,9 @@ export function MapImage({ "text-text-subtle flex items-center justify-center", )} > - + {size !== "card" && ( + + )} ); } diff --git a/web/src/features/maps/MapList.tsx b/web/src/features/maps/MapList.tsx index e5b5db0..1746878 100644 --- a/web/src/features/maps/MapList.tsx +++ b/web/src/features/maps/MapList.tsx @@ -1,5 +1,5 @@ // The Maps page's totals (maps, tiered maps, maps per tier), its search, sort, style and completion choices, -// and one row per map with its picture, tier and world record. Staff who manage maps also get a "No runs yet" tab +// and one card per map with its picture, tier and top three. 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 type { CSSProperties } from "react"; @@ -7,13 +7,13 @@ import { api, type Schemas } from "@/api/client"; import { signedInPlayer } from "@/features/auth/signedInPlayer"; import { currentStyles } from "@/features/ruleset/styles"; import { STEAMID } from "@/features/players/steamId"; -import { formatSince, formatTime } from "@/features/runs/time"; +import { formatSince } from "@/features/runs/time"; import { BulkUpload } from "@/features/staff/maps/BulkUpload"; import { UnplayedMaps } from "@/features/staff/maps/UnplayedMaps"; import { Avatar } from "@/ui/Avatar"; import { ButtonLink } from "@/ui/Button"; import { Card } from "@/ui/Card"; -import { Flag } from "@/ui/Flag"; +import { classNames } from "@/ui/classNames"; import { SearchField } from "@/ui/SearchField"; import { Link } from "@/ui/Link"; import { ChoiceBar } from "@/ui/ChoiceBar"; @@ -23,7 +23,9 @@ import { Pager } from "@/ui/Pager"; import { TierBadge } from "@/ui/TierBadge"; import { TierSpread } from "@/ui/TierSpread"; import { managesMaps } from "./MapHeader"; -import { MapImage } from "./MapImage"; +import { MapCard } from "./MapCard"; +import { mapPodiums } from "./mapPodiums"; +import cardStyles from "./MapCard.module.css"; import { MAP_NAME } from "./mapName"; import { tierParam } from "./tierParam"; import { avatarSrc } from "@/features/players/avatarSrc"; @@ -151,6 +153,7 @@ export async function MapList({ params }: { params: MapListParams }) { .catch(() => undefined); const list = result?.data; const style = list?.style ?? requestedStyle; + const podiums = await mapPodiums(list?.maps ?? [], style); const typedName = q.toLowerCase(); const offerSetUp = staff && @@ -205,7 +208,7 @@ export async function MapList({ params }: { params: MapListParams }) { return (
-

Maps

+

Maps

{list && ( ) : ( -
+

{q @@ -327,7 +330,7 @@ export async function MapList({ params }: { params: MapListParams }) {

    {list.maps.map((map, index) => (
  • - +
  • ))}
@@ -381,7 +392,7 @@ function MapStats({ newestHref: string; }) { const tiered = stats.by_tier.reduce((sum, count) => sum + count, 0); - const hasTiers = stats.by_tier.length > 0; + const hasTiers = stats.by_tier.length > 0 && stats.maps > 0; const newest = stats.newest.filter( (map) => selected == null || map.tier === selected, ); @@ -390,10 +401,24 @@ function MapStats({ ); if (!hasTiers && newest.length === 0 && playedThisWeek.length === 0) return null; + const weeklyScoped = + selected == null || + stats.tier === selected || + stats.played_this_week.length < 5 || + playedThisWeek.length === 5; + const hasWeekly = stats.maps > 0; + const singleSummary = Number(newest.length > 0) + Number(hasWeekly) === 1; return ( - + {hasTiers && ( -
+
0 && ( ({ name: map.name, @@ -414,10 +440,16 @@ function MapStats({ tierCount={tierCount} /> )} - {playedThisWeek.length > 0 && ( + {hasWeekly && ( ({ + empty={ + weeklyScoped + ? "No maps played in the last seven days." + : "Weekly activity for this tier could not be loaded." + } + singleSummary={singleSummary} + maps={(weeklyScoped ? playedThisWeek : []).map((map) => ({ name: map.name, tier: map.tier, detail: `${number.format(map.players)} ${map.players === 1 ? "player" : "players"}`, @@ -432,47 +464,70 @@ function MapStats({ /** One of the map stats' lists: a heading, linked to the matching sort if there is one, then a few maps with a detail each. */ function MapStatsList({ title, + empty, + singleSummary, href, maps, tierCount, }: { title: string; + empty?: string; + singleSummary: boolean; href?: string; maps: { name: string; tier?: number | null; detail: string }[]; tierCount: number | null | undefined; }) { return ( -
-

- {href ? ( - - {title} - +
+
+

+ {href ? ( + + {title} + + ) : ( + title + )} +

+ {maps.length === 0 ? ( +

{empty}

) : ( - title +
    + {maps.map((map) => ( +
  • + + {map.tier != null && tierCount != null ? ( + + ) : ( + + )} + + {map.name} + + + {map.detail} + + +
  • + ))} +
)} -

-
    - {maps.map((map) => ( -
  • - - {map.tier != null && tierCount != null && ( - - )} - - {map.name} - - {map.detail} - -
  • - ))} -
+
); } @@ -511,64 +566,3 @@ function FilterPlayer({ ); } - -function MapRow({ - map, - tierCount, -}: { - map: Schemas["MapSummary"]; - tierCount: number | null | undefined; -}) { - const wr = map.world_record; - 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`}`} - - - - - World record - - {wr ? ( - - - {formatTime(wr.time)} - - - {wr.player.name} - {wr.player.country_code && ( - - )} - - - ) : ( - - No record in this style - - )} - - - - ); -} diff --git a/web/src/features/maps/mapPodiums.ts b/web/src/features/maps/mapPodiums.ts new file mode 100644 index 0000000..ae9a469 --- /dev/null +++ b/web/src/features/maps/mapPodiums.ts @@ -0,0 +1,57 @@ +// Public main-track podiums for the map cards, cached briefly and fetched in bounded batches. +import { cacheLife } from "next/cache"; +import { api, type Schemas } from "@/api/client"; + +export type MapLeader = Pick< + Schemas["LeaderboardEntry"], + "rank" | "player" | "time" | "run_id" +>; + +export async function mapPodiums( + maps: Schemas["MapSummary"][], + style: string | null | undefined, +): Promise> { + const podiums = new Map(); + if (!style) return podiums; + // Avoid issuing a page's worth of independent requests to the beta API at once. + for (let offset = 0; offset < maps.length; offset += 6) { + const batch = await Promise.all( + maps.slice(offset, offset + 6).map(async (map) => { + if (!map.world_record) return [map.name, []] as const; + const leaders = await cachedPodium({ + map: map.name, + style, + record: map.world_record.run_id, + }).catch(() => null); + return [map.name, leaders] as const; + }), + ); + for (const [map, leaders] of batch) podiums.set(map, leaders); + if (batch.every(([, leaders]) => leaders === null)) break; + } + return podiums; +} + +async function cachedPodium(key: { + map: string; + style: string; + // A new WR changes the key, so cached cards cannot contradict the map list's winner. + record: number; +}): Promise { + "use cache"; + cacheLife({ stale: 30, revalidate: 30, expire: 300 }); + const { data, response } = await api.GET("/v1/maps/{map}/leaderboard", { + params: { + path: { map: key.map }, + query: { style: key.style, track: 0, limit: 3 }, + }, + signal: AbortSignal.timeout(5000), + }); + if (!data) throw new Error(`Map podium answered ${response.status}`); + return data.entries.map(({ rank, player, time, run_id }) => ({ + rank, + player, + time, + run_id, + })); +} diff --git a/web/src/ui/Avatar.tsx b/web/src/ui/Avatar.tsx index 6941c0e..6ca2e01 100644 --- a/web/src/ui/Avatar.tsx +++ b/web/src/ui/Avatar.tsx @@ -1,7 +1,7 @@ "use client"; // A player's picture, or their initials when there is none or it doesn't load (the API's avatar route before an // API that has it is deployed, or Steam's CDN failing). -import { useState } from "react"; +import { useCallback, useState } from "react"; import { classNames } from "./classNames"; type Size = "sm" | "md" | "lg" | "xl"; @@ -31,11 +31,19 @@ export function Avatar({ ); // The picture this element failed to load, so a new `src` gets its own try. const [failed, setFailed] = useState(); + // A cached failure can arrive before hydration attaches the error handler. + const imageRef = useCallback( + (image: HTMLImageElement | null) => { + if (image?.complete && image.naturalWidth === 0) setFailed(src); + }, + [src], + ); if (src && src !== failed) { // Steam serves avatars pre-sized from its CDN, so next/image's resizing would add nothing. return ( // eslint-disable-next-line @next/next/no-img-element diff --git a/web/src/ui/TierBadge.tsx b/web/src/ui/TierBadge.tsx index 02cfba7..60f6301 100644 --- a/web/src/ui/TierBadge.tsx +++ b/web/src/ui/TierBadge.tsx @@ -32,6 +32,7 @@ export function TierBadge({ /** E.g. a fill of its own, where it sits on a picture. */ className?: string; }) { + // The light foreground mix keeps small labels readable even at the darker end of the ramp. const style = { "--tier": tierColor(tier, tierCount) } as CSSProperties; return ( diff --git a/web/src/ui/TierSpread.tsx b/web/src/ui/TierSpread.tsx index f7a76c5..dede22a 100644 --- a/web/src/ui/TierSpread.tsx +++ b/web/src/ui/TierSpread.tsx @@ -1,40 +1,19 @@ -// 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. +// Map difficulty distribution and filters, sharing one aligned legend across screen sizes. +import { Check, RotateCcw } from "lucide-react"; 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 WIDTH = 14; const GAP = 0.6; -/** The reset uses the site accent; individual selections use their tier color. */ -const allTiersClasses = (chosen: boolean) => - classNames( - "flex h-7 w-full items-center justify-between gap-2 rounded-sm border px-2 text-sm font-medium transition-colors duration-(--duration-fast)", - chosen - ? "border-accent/40 bg-accent-soft text-accent hover:border-accent" - : "border-border-strong text-text-muted hover:border-text-muted hover:bg-text/4 hover:text-text", - ); - -const rowClasses = - "col-span-3 grid grid-cols-subgrid items-center rounded-sm px-2 py-0.5 ring-1 ring-inset transition-[background-color,box-shadow] duration-(--duration-fast)"; - -/** The inset outline marks selection without moving the compact rows. */ -const chosenTier = "bg-(--tier)/10 ring-(--tier)/40"; - export function TierSpread({ byTier, untiered, @@ -44,18 +23,13 @@ export function TierSpread({ /** Maps per tier, tier 1 first; its length is the tier count. */ byTier: number[]; untiered: number; - /** The tier the list is filtered to, if any. */ selected?: number; - /** Where a tier leads; null for the whole list. */ + /** 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, @@ -63,114 +37,27 @@ export function TierSpread({ (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)} - - -
  • + const columns = [slices.slice(0, half), slices.slice(half)].filter( + (tiers, index) => tiers.length > 0 || (index === 1 && untiered > 0), ); + const all = selected == null; + const chosen = selected != null ? byTier[selected - 1] : undefined; + const tieredShare = ((total - untiered) / total) * 100; return ( - <> -
    - {/* The donut's shares laid end to end. */} -
    - {slices.map( - ({ tier, count }) => - count > 0 && ( - - ), - )} - {untiered > 0 && } -
    -
    - - All tiers - - {number.format(total)} maps - - - {untiered > 0 && ( - - {number.format(untiered)} without a tier - - )} -
    -
      - {slices.map(({ tier, count }) => ( -
    • - - - - {number.format(count)} - - -
    • - ))} -
    -
    -
    - +
    + + {untiered > 0 && ( )} {slices.map( @@ -191,6 +78,7 @@ export function TierSpread({ key={tier} href={tierHref(selected === tier ? null : tier)} scroll={false} + tabIndex={-1} aria-label={`Tier ${tier}: ${number.format(count)} maps`} > {`Tier ${tier}: ${number.format(count)} maps`} @@ -201,84 +89,162 @@ export function TierSpread({ fill="none" pathLength={100} strokeWidth={WIDTH} - // Very small tiers still show as a sliver rather than vanishing into the gap. strokeDasharray={`${Math.max(length - GAP, 0.3)} 100`} strokeDashoffset={-start} style={ { "--tier": tierColor(tier, tierCount) } as CSSProperties } className={classNames( - "stroke-(--tier) transition-[opacity,stroke-width] duration-(--duration-base) hover:stroke-[19]", - dimmed(tier) && "opacity-25", - selected === tier && "stroke-[19]", + "stroke-(--tier) transition-[opacity,stroke-width] duration-(--duration-fast) hover:stroke-[16] hover:opacity-100", + !all && selected !== tier && "opacity-30", + selected === tier && "stroke-[16]", )} /> ), )} - {/* 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)} maps - - -
      + + {all ? "All" : `T${selected}`} + + {chosen != null && ( + - {slices.slice(0, half).map(tierRow)} - {slices.slice(half).map(tierRow)} - {untiered > 0 && ( -
    • - No tier - - {number.format(untiered)} - - - {percent.format(untiered / total)} - -
    • + {number.format(chosen)} {chosen === 1 ? "map" : "maps"} +
      + )} + + +
    + All tiers + + + {number.format(total)} maps + + + {/* Intrinsic columns keep counts close to badges. With no row padding, the reset's edges + coincide with the first badge and the last percentage, including its selected background. */} +
    + {columns.map((tiers, index) => ( +
      + {tiers.map(({ tier, count }) => { + const active = selected === tier; + return ( +
    • + + + + {number.format(count)} + + + {percent.format(count / total)} + + +
    • + ); + })} + {index === columns.length - 1 && untiered > 0 && ( +
    • + No tier + + {number.format(untiered)} + + + {percent.format(untiered / total)} + +
    • + )} +
    + ))}
    -
    - + +
    ); } diff --git a/web/src/ui/tokens.css b/web/src/ui/tokens.css index 80c0cf8..3c46923 100644 --- a/web/src/ui/tokens.css +++ b/web/src/ui/tokens.css @@ -55,6 +55,10 @@ /* Below 360px (the narrowest common phones) the header and home headline need to shed a little width. */ --breakpoint-xs: 22.5rem; + /* Halfway from the old 72rem sheet to the viewport, without removing the desktop gutters. */ + --container-site: calc((100% + 72rem) / 2); + --container-content: calc((100% + 56rem) / 2); + --font-*: initial; --font-sans: var(--font-geist), ui-sans-serif, system-ui, sans-serif; /* Game servers' names, as a server browser shows them. */