diff --git a/api/.sqlx/query-05845fdb39cec480cfa34441c591594827f4b38fa1cc1b81d2974fc8141fa7b5.json b/api/.sqlx/query-05845fdb39cec480cfa34441c591594827f4b38fa1cc1b81d2974fc8141fa7b5.json deleted file mode 100644 index 5127cbf..0000000 --- a/api/.sqlx/query-05845fdb39cec480cfa34441c591594827f4b38fa1cc1b81d2974fc8141fa7b5.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "\n SELECT shown.map AS \"map!\", shown.track AS \"track!\", shown.time AS \"time!\",\n CASE WHEN NOT shown.legacy THEN 1 + (\n SELECT count(*) FROM personal_bests faster\n WHERE faster.map_id = shown.map_id AND faster.style = $2 AND faster.track = shown.track\n AND faster.time < shown.time) END AS rank,\n shown.legacy AS \"legacy!\", shown.id AS \"id!\", shown.finished_at\n FROM (\n SELECT DISTINCT ON (both_kinds.map, both_kinds.track) both_kinds.*\n FROM (\n SELECT m.name AS map, pb.map_id, pb.track, pb.time, false AS legacy, pb.run_id AS id,\n pb.finished_at\n FROM personal_bests pb\n JOIN maps m ON m.id = pb.map_id\n WHERE $3 AND pb.player_steamid64 = $1 AND pb.style = $2 AND pb.track = $4\n UNION ALL\n SELECT lm.name, NULL::bigint, $4::smallint, l.time, true, l.id::bigint, l.finished_at\n FROM legacy_personal_bests l\n JOIN legacy_maps lm ON lm.id = l.map_id\n WHERE l.player_steamid64 = $1 AND NOT EXISTS (SELECT 1 FROM records_bans b WHERE b.player_steamid64 = $1)\n ) both_kinds\n WHERE $5::text IS NULL OR (both_kinds.map, both_kinds.track) > ($5, $6::smallint)\n ORDER BY both_kinds.map, both_kinds.track, both_kinds.time, both_kinds.legacy\n LIMIT $7\n ) shown\n ORDER BY shown.map, shown.track\n ", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "map!", - "type_info": "Text", - "origin": "Expression" - }, - { - "ordinal": 1, - "name": "track!", - "type_info": "Int2", - "origin": "Expression" - }, - { - "ordinal": 2, - "name": "time!", - "type_info": "Float8", - "origin": "Expression" - }, - { - "ordinal": 3, - "name": "rank", - "type_info": "Int8", - "origin": "Expression" - }, - { - "ordinal": 4, - "name": "legacy!", - "type_info": "Bool", - "origin": "Expression" - }, - { - "ordinal": 5, - "name": "id!", - "type_info": "Int8", - "origin": "Expression" - }, - { - "ordinal": 6, - "name": "finished_at", - "type_info": "Timestamptz", - "origin": "Expression" - } - ], - "parameters": { - "Left": [ - "Int8", - "Text", - "Bool", - "Int2", - "Text", - "Int2", - "Int8" - ] - }, - "nullable": [ - null, - null, - null, - null, - null, - null, - null - ] - }, - "hash": "05845fdb39cec480cfa34441c591594827f4b38fa1cc1b81d2974fc8141fa7b5" -} diff --git a/api/.sqlx/query-5d5552b38e89f4ba65a4739c79d3902426a3541c08ea94eb96efc73cfdd91d28.json b/api/.sqlx/query-d229738260622b500ce9606ced26758e381bc932126584a48c813acb6e272509.json similarity index 50% rename from api/.sqlx/query-5d5552b38e89f4ba65a4739c79d3902426a3541c08ea94eb96efc73cfdd91d28.json rename to api/.sqlx/query-d229738260622b500ce9606ced26758e381bc932126584a48c813acb6e272509.json index fe7f77d..2c5680d 100644 --- a/api/.sqlx/query-5d5552b38e89f4ba65a4739c79d3902426a3541c08ea94eb96efc73cfdd91d28.json +++ b/api/.sqlx/query-d229738260622b500ce9606ced26758e381bc932126584a48c813acb6e272509.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT own.style AS \"style!\", own.map AS \"map!\", own.track AS \"track!\", own.time AS \"time!\",\n 1 + (SELECT count(*) FROM personal_bests faster\n WHERE faster.map_id = own.map_id AND faster.style = own.style\n AND faster.track = own.track AND faster.time < own.time) AS \"rank!\",\n own.run_id AS \"run_id!\", own.finished_at AS \"finished_at!\"\n FROM (\n SELECT pb.style, pb.map_id, m.name AS map, pb.track, pb.time, pb.run_id, pb.finished_at\n FROM personal_bests pb\n JOIN maps m ON m.id = pb.map_id\n WHERE pb.player_steamid64 = $1\n AND ($2::text IS NULL OR pb.style = $2)\n AND ($3::text IS NULL OR (m.name, pb.track) > ($3, $4::smallint))\n AND ($6::bool IS NULL OR (pb.track > 0) = $6)\n AND (NOT $7 OR EXISTS (\n SELECT 1 FROM world_record_holders h\n WHERE h.player_steamid64 = $1 AND h.map_id = pb.map_id AND h.style = pb.style\n AND h.track = pb.track))\n AND ($9::timestamptz IS NULL OR (pb.finished_at, pb.run_id) < ($9, $10::int8))\n ORDER BY CASE WHEN $8 THEN pb.finished_at END DESC, CASE WHEN $8 THEN pb.run_id END DESC,\n pb.style, m.name, pb.track\n LIMIT $5\n ) own\n ORDER BY CASE WHEN $8 THEN own.finished_at END DESC, CASE WHEN $8 THEN own.run_id END DESC,\n own.style, own.map, own.track\n ", + "query": "\n SELECT own.style AS \"style!\", own.map AS \"map!\", own.track AS \"track!\", own.time AS \"time!\",\n 1 + (SELECT count(*) FROM personal_bests faster\n WHERE faster.map_id = own.map_id AND faster.style = own.style\n AND faster.track = own.track AND faster.time < own.time) AS \"rank!\",\n (SELECT min(best.time) FROM personal_bests best\n WHERE best.map_id = own.map_id AND best.style = own.style\n AND best.track = own.track) AS \"world_record_time!\",\n own.run_id AS \"run_id!\", own.finished_at AS \"finished_at!\", tier.tier AS \"tier?\"\n FROM (\n SELECT pb.style, pb.map_id, m.name AS map, pb.track, pb.time, pb.run_id, pb.finished_at\n FROM personal_bests pb\n JOIN maps m ON m.id = pb.map_id\n WHERE pb.player_steamid64 = $1\n AND ($2::text IS NULL OR pb.style = $2)\n AND ($3::text IS NULL OR (m.name, pb.track) > ($3, $4::smallint))\n AND ($6::bool IS NULL OR (pb.track > 0) = $6)\n AND (NOT $7 OR EXISTS (\n SELECT 1 FROM world_record_holders h\n WHERE h.player_steamid64 = $1 AND h.map_id = pb.map_id AND h.style = pb.style\n AND h.track = pb.track))\n AND ($9::timestamptz IS NULL OR (pb.finished_at, pb.run_id) < ($9, $10::int8))\n ORDER BY CASE WHEN $8 THEN pb.finished_at END DESC, CASE WHEN $8 THEN pb.run_id END DESC,\n pb.style, m.name, pb.track\n LIMIT $5\n ) own\n LEFT JOIN LATERAL (SELECT tier FROM map_tiers WHERE map_id = own.map_id AND track = own.track\n ORDER BY assigned_at DESC LIMIT 1) tier ON $11\n ORDER BY CASE WHEN $8 THEN own.finished_at END DESC, CASE WHEN $8 THEN own.run_id END DESC,\n own.style, own.map, own.track\n ", "describe": { "columns": [ { @@ -55,6 +55,12 @@ }, { "ordinal": 5, + "name": "world_record_time!", + "type_info": "Float8", + "origin": "Expression" + }, + { + "ordinal": 6, "name": "run_id!", "type_info": "Int8", "origin": { @@ -65,7 +71,7 @@ } }, { - "ordinal": 6, + "ordinal": 7, "name": "finished_at!", "type_info": "Timestamptz", "origin": { @@ -74,6 +80,17 @@ "name": "finished_at" } } + }, + { + "ordinal": 8, + "name": "tier?", + "type_info": "Int2", + "origin": { + "Table": { + "table": "map_tiers", + "name": "tier" + } + } } ], "parameters": { @@ -87,7 +104,8 @@ "Bool", "Bool", "Timestamptz", - "Int8" + "Int8", + "Bool" ] }, "nullable": [ @@ -96,9 +114,11 @@ false, false, null, + null, + false, false, false ] }, - "hash": "5d5552b38e89f4ba65a4739c79d3902426a3541c08ea94eb96efc73cfdd91d28" + "hash": "d229738260622b500ce9606ced26758e381bc932126584a48c813acb6e272509" } diff --git a/api/.sqlx/query-fe47d13f296be60170a39f1f7bfd568993ed49e0f088a4e391206d71d84e8e4e.json b/api/.sqlx/query-fe47d13f296be60170a39f1f7bfd568993ed49e0f088a4e391206d71d84e8e4e.json new file mode 100644 index 0000000..7d1d2fc --- /dev/null +++ b/api/.sqlx/query-fe47d13f296be60170a39f1f7bfd568993ed49e0f088a4e391206d71d84e8e4e.json @@ -0,0 +1,91 @@ +{ + "db_name": "PostgreSQL", + "query": "\n SELECT shown.map AS \"map!\", shown.track AS \"track!\", shown.time AS \"time!\",\n CASE WHEN NOT shown.legacy THEN 1 + (\n SELECT count(*) FROM personal_bests faster\n WHERE faster.map_id = shown.map_id AND faster.style = $2 AND faster.track = shown.track\n AND faster.time < shown.time) END AS rank,\n CASE WHEN NOT shown.legacy THEN (\n SELECT min(best.time) FROM personal_bests best\n WHERE best.map_id = shown.map_id AND best.style = $2 AND best.track = shown.track)\n END AS world_record_time,\n shown.legacy AS \"legacy!\", shown.id AS \"id!\", shown.finished_at, tier.tier AS \"tier?\"\n FROM (\n SELECT DISTINCT ON (both_kinds.map, both_kinds.track) both_kinds.*\n FROM (\n SELECT m.name AS map, pb.map_id, pb.track, pb.time, false AS legacy, pb.run_id AS id,\n pb.finished_at\n FROM personal_bests pb\n JOIN maps m ON m.id = pb.map_id\n WHERE $3 AND pb.player_steamid64 = $1 AND pb.style = $2 AND pb.track = $4\n UNION ALL\n SELECT lm.name, NULL::bigint, $4::smallint, l.time, true, l.id::bigint, l.finished_at\n FROM legacy_personal_bests l\n JOIN legacy_maps lm ON lm.id = l.map_id\n WHERE l.player_steamid64 = $1 AND NOT EXISTS (SELECT 1 FROM records_bans b WHERE b.player_steamid64 = $1)\n ) both_kinds\n WHERE $5::text IS NULL OR (both_kinds.map, both_kinds.track) > ($5, $6::smallint)\n ORDER BY both_kinds.map, both_kinds.track, both_kinds.time, both_kinds.legacy\n LIMIT $7\n ) shown\n -- A legacy row's map_id is NULL, so it finds no tier.\n LEFT JOIN LATERAL (SELECT tier FROM map_tiers WHERE map_id = shown.map_id AND track = shown.track\n ORDER BY assigned_at DESC LIMIT 1) tier ON $8\n ORDER BY shown.map, shown.track\n ", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "map!", + "type_info": "Text", + "origin": "Expression" + }, + { + "ordinal": 1, + "name": "track!", + "type_info": "Int2", + "origin": "Expression" + }, + { + "ordinal": 2, + "name": "time!", + "type_info": "Float8", + "origin": "Expression" + }, + { + "ordinal": 3, + "name": "rank", + "type_info": "Int8", + "origin": "Expression" + }, + { + "ordinal": 4, + "name": "world_record_time", + "type_info": "Float8", + "origin": "Expression" + }, + { + "ordinal": 5, + "name": "legacy!", + "type_info": "Bool", + "origin": "Expression" + }, + { + "ordinal": 6, + "name": "id!", + "type_info": "Int8", + "origin": "Expression" + }, + { + "ordinal": 7, + "name": "finished_at", + "type_info": "Timestamptz", + "origin": "Expression" + }, + { + "ordinal": 8, + "name": "tier?", + "type_info": "Int2", + "origin": { + "Table": { + "table": "map_tiers", + "name": "tier" + } + } + } + ], + "parameters": { + "Left": [ + "Int8", + "Text", + "Bool", + "Int2", + "Text", + "Int2", + "Int8", + "Bool" + ] + }, + "nullable": [ + null, + null, + null, + null, + null, + null, + null, + null, + true + ] + }, + "hash": "fe47d13f296be60170a39f1f7bfd568993ed49e0f088a4e391206d71d84e8e4e" +} diff --git a/api/crates/api/src/legacy.rs b/api/crates/api/src/legacy.rs index a37842f..4eca276 100644 --- a/api/crates/api/src/legacy.rs +++ b/api/crates/api/src/legacy.rs @@ -176,8 +176,10 @@ mod tests { use sqlx::PgPool; use crate::{ + maps::MapName, + policies::{Policy, TiersPolicy}, runs::tests::{run, setup}, - test_client, + staff, test_client, }; const GABE: &str = "76561197960287930"; @@ -362,6 +364,19 @@ mod tests { 0 ); + staff::policies::publish_policy( + &db, + None, + None, + &Policy::Tiers(TiersPolicy { count: 5 }), + None, + ) + .await + .unwrap(); + let badges = MapName::try_from("bhop_badges".to_owned()).unwrap(); + staff::maps::set_tier(&db, None, &badges, 0, 3) + .await + .unwrap(); let pbs = get( &db, &format!("/v1/players/{ALICE}/personal-bests?style=normal&view=legacy"), @@ -374,6 +389,14 @@ mod tests { .map(|pb| (pb["map"].as_str().unwrap(), pb["time"].as_f64().unwrap())) .collect(); assert_eq!(maps, [("bhop_badges", 25.0), ("bhop_oldonly", 40.0)]); + // Legacy runs have no tier or record time, even on a map whose board has both. + assert!( + pbs["personal_bests"] + .as_array() + .unwrap() + .iter() + .all(|pb| pb["tier"].is_null() && pb["world_record_time"].is_null()) + ); let gabe = get( &db, @@ -386,6 +409,8 @@ mod tests { (Some(30.0), Some(false)) ); assert_eq!(pb["rank"], 1); + assert_eq!(pb["tier"], 3); + assert_eq!(pb["world_record_time"], 30.0); let found = get(&db, "/v1/players?q=alic").await; assert_eq!(found["players"][0]["steamid64"], ALICE); diff --git a/api/crates/api/src/players/personal_bests.rs b/api/crates/api/src/players/personal_bests.rs index 5fc38aa..8238094 100644 --- a/api/crates/api/src/players/personal_bests.rs +++ b/api/crates/api/src/players/personal_bests.rs @@ -16,6 +16,7 @@ use crate::{ app::AppState, error::{ApiError, ErrorBody}, legacy::{self, View}, + maps::tiers, }; pub const DEFAULT_LIMIT: i64 = 50; @@ -66,8 +67,14 @@ pub struct PersonalBest { pub map: String, /// 0 is the main track, 1 and up are bonuses. pub track: i16, + /// The board's tier. None while tiers aren't in force or staff haven't set this board's, and for a legacy + /// run. + pub tier: Option, /// Seconds. pub time: f64, + /// The board's 2.0 record time, as on its map leaderboard, so a client can show the gap to it. None for a + /// legacy run. + pub world_record_time: Option, /// Placement on the map's 2.0 leaderboard for this style and track. Equal times share a placement. None /// for a legacy run, which has no 2.0 placement. pub rank: Option, @@ -99,13 +106,14 @@ pub(super) struct Selection<'a> { } /// The player's personal bests with placements, as `selection` asks; `after` continues after a position, and -/// `limit` caps the count (None for all of them). +/// `limit` caps the count (None for all of them). `tiers_in_force` is whether a tier count is published. pub(super) async fn personal_bests( db: &PgPool, steamid64: SteamId64, selection: Selection<'_>, after: Option<&Position>, limit: Option, + tiers_in_force: bool, ) -> Result, sqlx::Error> { let (after_map, after_time) = match after { Some(Position::ByMap(map, track)) => (Some((map.as_str(), *track)), None), @@ -114,14 +122,18 @@ pub(super) async fn personal_bests( }; // The player's own rows are picked and paged first; each one's placement is then one more than the // personal bests faster than it on its board, an index range on `personal_bests_board`. Ranking whole - // boards and keeping the player's rows read every board they're on. + // boards and keeping the player's rows read every board they're on. Record times and tiers too are + // looked up for the page's rows alone. let rows = sqlx::query!( r#" SELECT own.style AS "style!", own.map AS "map!", own.track AS "track!", own.time AS "time!", 1 + (SELECT count(*) FROM personal_bests faster WHERE faster.map_id = own.map_id AND faster.style = own.style AND faster.track = own.track AND faster.time < own.time) AS "rank!", - own.run_id AS "run_id!", own.finished_at AS "finished_at!" + (SELECT min(best.time) FROM personal_bests best + WHERE best.map_id = own.map_id AND best.style = own.style + AND best.track = own.track) AS "world_record_time!", + own.run_id AS "run_id!", own.finished_at AS "finished_at!", tier.tier AS "tier?" FROM ( SELECT pb.style, pb.map_id, m.name AS map, pb.track, pb.time, pb.run_id, pb.finished_at FROM personal_bests pb @@ -139,6 +151,8 @@ pub(super) async fn personal_bests( pb.style, m.name, pb.track LIMIT $5 ) own + LEFT JOIN LATERAL (SELECT tier FROM map_tiers WHERE map_id = own.map_id AND track = own.track + ORDER BY assigned_at DESC LIMIT 1) tier ON $11 ORDER BY CASE WHEN $8 THEN own.finished_at END DESC, CASE WHEN $8 THEN own.run_id END DESC, own.style, own.map, own.track "#, @@ -151,7 +165,8 @@ pub(super) async fn personal_bests( selection.records_only, selection.recent_first, after_time.map(|(finished_at, _)| finished_at), - after_time.map(|(_, run_id)| run_id) + after_time.map(|(_, run_id)| run_id), + tiers_in_force ) .fetch_all(db) .await?; @@ -162,7 +177,9 @@ pub(super) async fn personal_bests( style: row.style, map: row.map, track: row.track, + tier: row.tier, time: row.time, + world_record_time: Some(row.world_record_time), rank: Some(row.rank), legacy: false, run_id: row.run_id, @@ -174,13 +191,14 @@ pub(super) async fn personal_bests( /// The player's main-track personal bests in the legacy board's style for the "2.0 + pre-2.0" or "Pre-2.0" /// view, sorted by map. With both, each map shows the faster of their 2.0 and legacy runs (the 2.0 one on /// equal times). A player banned from records shows no legacy runs, as on the -/// old site. +/// old site. Only the 2.0 runs can have a tier and a record time. async fn view_personal_bests( db: &PgPool, steamid64: SteamId64, view: View, after: Option<(&str, i16)>, limit: i64, + tiers_in_force: bool, ) -> Result, sqlx::Error> { let rows = sqlx::query!( r#" @@ -189,7 +207,11 @@ async fn view_personal_bests( SELECT count(*) FROM personal_bests faster WHERE faster.map_id = shown.map_id AND faster.style = $2 AND faster.track = shown.track AND faster.time < shown.time) END AS rank, - shown.legacy AS "legacy!", shown.id AS "id!", shown.finished_at + CASE WHEN NOT shown.legacy THEN ( + SELECT min(best.time) FROM personal_bests best + WHERE best.map_id = shown.map_id AND best.style = $2 AND best.track = shown.track) + END AS world_record_time, + shown.legacy AS "legacy!", shown.id AS "id!", shown.finished_at, tier.tier AS "tier?" FROM ( SELECT DISTINCT ON (both_kinds.map, both_kinds.track) both_kinds.* FROM ( @@ -208,6 +230,9 @@ async fn view_personal_bests( ORDER BY both_kinds.map, both_kinds.track, both_kinds.time, both_kinds.legacy LIMIT $7 ) shown + -- A legacy row's map_id is NULL, so it finds no tier. + LEFT JOIN LATERAL (SELECT tier FROM map_tiers WHERE map_id = shown.map_id AND track = shown.track + ORDER BY assigned_at DESC LIMIT 1) tier ON $8 ORDER BY shown.map, shown.track "#, steamid64.get(), @@ -216,7 +241,8 @@ async fn view_personal_bests( legacy::TRACK, after.map(|(map, _)| map), after.map(|(_, track)| track), - limit + limit, + tiers_in_force ) .fetch_all(db) .await?; @@ -227,7 +253,9 @@ async fn view_personal_bests( style: legacy::STYLE.to_owned(), map: row.map, track: row.track, + tier: row.tier, time: row.time, + world_record_time: row.world_record_time, rank: row.rank, legacy: row.legacy, run_id: row.id, @@ -333,6 +361,7 @@ pub async fn player_personal_bests( return Err(ApiError::NotFound("SourceJump has no such player")); } + let tiers_in_force = tiers::tier_count(&state.db).await?.is_some(); let rows = if view == View::Current { let selection = Selection { style: query.style.as_deref(), @@ -346,6 +375,7 @@ pub async fn player_personal_bests( selection, after.as_ref(), Some(limit + 1), + tiers_in_force, ) .await? } else { @@ -358,7 +388,7 @@ pub async fn player_personal_bests( } None => None, }; - view_personal_bests(&state.db, steamid64, view, after, limit + 1).await? + view_personal_bests(&state.db, steamid64, view, after, limit + 1, tiers_in_force).await? }; let (personal_bests, next_cursor) = split_page( rows, diff --git a/api/crates/api/src/players/profile.rs b/api/crates/api/src/players/profile.rs index 3dd23fa..28d6dd9 100644 --- a/api/crates/api/src/players/profile.rs +++ b/api/crates/api/src/players/profile.rs @@ -20,6 +20,7 @@ use crate::{ app::AppState, error::{ApiError, ErrorBody}, leaderboards::standings, + maps::tiers, }; #[derive(Debug, Serialize, Deserialize, ToSchema)] @@ -52,6 +53,9 @@ pub struct PlayerProfile { /// Maps they have a legacy run on, none for a player banned from records. When there are any, the /// normal style's personal bests have the "2.0 + pre-2.0" and "Pre-2.0" views. pub legacy_maps: i64, + /// Number of tiers in force; None while the community hasn't set tiers, and personal bests then have no + /// tier. + pub tier_count: Option, } #[derive(Debug, Default, Serialize, Deserialize, ToSchema)] @@ -133,6 +137,7 @@ pub async fn player_profile( let map_count = crate::maps::played_count(&state.db).await?; let legacy_maps = legacy.as_ref().map_or(0, |legacy| legacy.maps); let shown = details::shown(&mut *state.db.acquire().await?, steamid64).await?; + let tier_count = tiers::tier_count(&state.db).await?; let Some(player) = player else { // Known only from the old site: its name, avatar and country as it last had them. @@ -154,6 +159,7 @@ pub async fn player_profile( .await? .draft, legacy_maps, + tier_count, })); }; @@ -165,7 +171,7 @@ pub async fn player_profile( ); let all_styles = totals(&state.db, steamid64).await?; - let mut styles = styles_of(&state.db, steamid64).await?; + let mut styles = styles_of(&state.db, steamid64, tier_count.is_some()).await?; for standing in standings_of(&state.db, steamid64).await? { if let Some(style) = styles.iter_mut().find(|s| s.style == standing.style) { let place = Some(StyleStanding { @@ -198,6 +204,7 @@ pub async fn player_profile( all_styles, points_draft, legacy_maps, + tier_count, })) } @@ -251,6 +258,7 @@ async fn totals(db: &sqlx::PgPool, steamid64: SteamId64) -> Result Result, sqlx::Error> { let counts = sqlx::query!( r#" @@ -275,9 +283,15 @@ async fn styles_of( tracks: Some(Tracks::Main), ..Selection::default() }; - let first_page = - personal_bests::personal_bests(db, steamid64, selection, None, Some(DEFAULT_LIMIT + 1)) - .await?; + let first_page = personal_bests::personal_bests( + db, + steamid64, + selection, + None, + Some(DEFAULT_LIMIT + 1), + tiers_in_force, + ) + .await?; let (personal_bests, next_cursor) = personal_bests::split_page(first_page, page_size, false); styles.push(PlayerStyle { @@ -416,6 +430,8 @@ mod tests { .await .json(); assert_eq!(main_standing(&profile), None, "no points without tiers"); + assert_eq!(profile.tier_count, None); + assert_eq!(profile.styles[0].personal_bests[0].tier, None); staff::policies::publish_policy( &db, @@ -434,6 +450,13 @@ mod tests { .await .json(); assert_eq!(main_standing(&profile), Some(rank), "{player}"); + assert_eq!(profile.tier_count, Some(5)); + assert_eq!(profile.styles[0].personal_bests[0].tier, Some(1)); + // The record holder's own time, the faster time for the player behind. + assert_eq!( + profile.styles[0].personal_bests[0].world_record_time, + Some(20.0) + ); assert!(profile.styles[0].bonus_standing.is_none()); assert!(profile.points_draft); } diff --git a/api/openapi.json b/api/openapi.json index fb89b9b..47b6a34 100644 --- a/api/openapi.json +++ b/api/openapi.json @@ -7958,6 +7958,14 @@ "style": { "type": "string" }, + "tier": { + "type": [ + "integer", + "null" + ], + "format": "int32", + "description": "The board's tier. None while tiers aren't in force or staff haven't set this board's, and for a legacy\nrun." + }, "time": { "type": "number", "format": "double", @@ -7967,6 +7975,14 @@ "type": "integer", "format": "int32", "description": "0 is the main track, 1 and up are bonuses." + }, + "world_record_time": { + "type": [ + "number", + "null" + ], + "format": "double", + "description": "The board's 2.0 record time, as on its map leaderboard, so a client can show the gap to it. None for a\nlegacy run." } } }, @@ -8215,6 +8231,14 @@ "$ref": "#/components/schemas/PlayerStyle" }, "description": "One entry per style they hold a personal best in, sorted by style key. Counts are 2.0 alone." + }, + "tier_count": { + "type": [ + "integer", + "null" + ], + "format": "int32", + "description": "Number of tiers in force; None while the community hasn't set tiers, and personal bests then have no\ntier." } } }, diff --git a/docs/design-system.md b/docs/design-system.md index e90ca82..9e35609 100644 --- a/docs/design-system.md +++ b/docs/design-system.md @@ -6,7 +6,7 @@ One visual language that every page is built from, so pages can't drift apart. S - A slate sheet (`bg`, `shadow-sheet`) between darker gutters. 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. - Play for everything. Its digits are all the same width, so times line up in columns without a second font. -- Corners: `rounded-sm` (4px) for badges, `rounded-md` (8px) for controls and rows, `rounded-lg` (12px) only for padded cards and dialogs. +- 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. ## Tokens `web/src/ui/tokens.css` holds every color, type size, radius, shadow and easing as Tailwind theme variables. Tailwind's own palette, radii, type scale and shadows are cleared, so `bg-red-500` or `rounded-3xl` don't compile. Spacing keeps Tailwind's 4px grid. @@ -31,11 +31,11 @@ One visual language that every page is built from, so pages can't drift apart. S | `TierBadge` | `tier` and `tierCount` from the API | | `Avatar` | Steam avatar or initials; `sm` to `xl` | | `Flag` | Country flag from an ISO code, a grey placeholder without one; `hint` replaces its tooltip | -| `Table` + `TableHead`/`TableBody`/`TableRow`/`TableHeaderCell`/`TableCell` | Leaderboards and staff lists; `numeric` cells right-align, `wrap` cells let long names wrap. Scrolls sideways inside its frame when too wide | +| `Table` + `TableHead`/`TableBody`/`TableRow`/`TableHeaderCell`/`TableCell` | Leaderboards, staff lists; `numeric` cells right-align, `centered` heads center on narrow marks, `wrap` cells wrap. Scrolls sideways if too wide | | `Tabs` | Panels on one page; `underline` or `segmented` | | `LinkTabs` | Looks like `Tabs`, but each tab is a link: a view the server renders, such as the Maps page's sort | | `Segmented` | Looks like segmented `Tabs`, for a choice that changes the view in place (a server's activity range, a post's kind). The chosen option is in the accent | -| `ChoiceMenu` | "Label Value ▾": one choice from a list, in a `Menu` of radio items, changing the view in place, or following each option's `href` on a server page. Boards, profiles and the Maps page use a row of them (Style, Track, Runs; Sort, Records in; lead, 2026-10-26); quiet options are dimmed but choosable, disabled ones dimmed and kept in place. On a phone each takes a full row, label left and value right | +| `ChoiceMenu` | "Label Value ▾": one choice from a list, in a `Menu` of radio items, changing the view in place, or following each option's `href` on a server page. Boards, profiles and the Maps page use a row of them (Style, Track, Runs; Sort, Records in; lead, 2026-10-26); quiet options are dimmed but choosable, disabled ones dimmed and kept in place. Word-width on phones too, so they sit side by side | | `ChoiceBar` | The row those menus sit in, with any tabs beside them. Every page uses it, so the spacing between choices stays the same everywhere | | `Pager` | Previous and next under a paged list; `param`: its address key | | `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 | @@ -43,7 +43,7 @@ One visual language that every page is built from, so pages can't drift apart. S | `LineChart` | One count over time from zero (players online). Drawn in a fixed box stretched by CSS, so it fills its container 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` | How many maps hold each tier: a donut in tier colors beside each tier's count and share; each slice and row links to that tier's maps, the others dim, and "All" closes the list (Maps page) | | `Tooltip` | Hint on hover and focus; the child must be focusable | -| `Menu`, `MenuItem`, `MenuLink`, `MenuSeparator` | Menu button (account, mobile sections) | +| `Menu`, `MenuItem`, `MenuLink`, `MenuSeparator` | Menu button (account; `sheet`: phone menu) | | `Dialog` | Controlled modal (`open`, `onClose`). A field marked `data-autofocus` takes focus on each opening (React's `autoFocus` fires only on mount). Closes itself, without calling `onClose`, when its page is hidden for Back | | `BrandIcon`, `SteamButton` | Community and Steam logos (`colored`: in their own colors); Steam sign-in | | `Input`, `SearchField`, `Textarea`, `CountUp` | Text field with optional icon; search, button inside; multi-line field; animated number | @@ -65,7 +65,7 @@ Named utilities, so pages never write their own transitions: - `motion-reveal`: a section rising in as it scrolls into view (scroll-driven; browsers without it show it at once). - `motion-settle`: a large picture easing out of a slight zoom as the page opens (the home header). - `HeaderDepth` (`features/home/`): the home header's picture leans with the mouse, by a depth map of it (`scripts/header-depth.py`; rerun it when the picture changes). Dust drifts in the light shaft, and a click sends cyan traces crawling over the surfaces (`headerTraces.ts`). WebGL, running only while the header is on screen; off on touch screens and with reduced motion. -- `motion-pop`: a popover menu fading in with a slight drop and grow, and fading out as it closes (`Menu`). +- `motion-pop`: a menu fading in with a slight drop and grow (`Menu`); `motion-fade`: its `sheet`'s dim. - `CountUp`: counts up when scrolled into view, and from the old value when it changes. A number already in view when the page loads stays as it is. - `page-fade`: between pages (see Navigation). diff --git a/docs/site-api.md b/docs/site-api.md index 03f78b9..3c832e4 100644 --- a/docs/site-api.md +++ b/docs/site-api.md @@ -10,8 +10,8 @@ Players sign in with Steam (OpenID 2.0); the endpoints answer browsers (redirect - `SJ_PUBLIC_URL` is where players reach the site; redirects and the origin check use it. ## Players and privileges -- Profiles take a SteamID64, SteamID2 or SteamID3 and answer with the SteamID64. Placements rank personal bests per map, style and track; equal times share a place. -- Per style, a profile counts completed maps (main tracks, out of the map list's count), completed bonuses and world records, and carries the first 50 main-track personal bests by map; `…/personal-bests?style=&tracks=main|bonuses&cursor=` pages on, and `records=true` keeps only world records (2.0 only). Without `style` it lists every style, newest first; `all_styles` counts across styles. Ranks: `main_standing`, `bonus_standing` (lead, 2026-11-04). +- Profiles take a SteamID64, SteamID2 or SteamID3 and answer with a SteamID64. +- Per style, a profile counts completed maps (main tracks, out of the map list's count), completed bonuses and world records, and carries the first 50 main-track personal bests by map; `…/personal-bests?style=&tracks=main|bonuses&cursor=` pages on; `records=true` keeps only 2.0 world records. Without `style`, every style, newest first; `all_styles` counts across styles. Ranks: `main_standing`, `bonus_standing` (lead, 2026-11-04). Personal bests have a placement (ties share one), `tier` and `world_record_time`; profiles `tier_count`. - `PUT /v1/players/{player}/details` (rules in `players/details.rs`): setup and a country (`GET /v1/countries`), a save per 5 s; others' need `manage_bans` and a logged reason. Old-site setup shows first. - Avatar, country (unless the player picked one) and (until a run gives one) name come from their public Steam profile XML, fetched at sign-in, and when a day old after a run or a view (an hour after a failed one): one request per 2 s, 50 queued, one per player. Country names map to ISO codes in `players/countries.rs`. - Staff privileges are a bitmap in `players.privileges` (`players/privileges.rs`). Bit positions never change; the API names privileges and never sends numbers. `players.restrictions` is unused (bans hold restrictions). The CLI's `privileges grant …`, `revoke`, `list` and the staff tools share `staff/privileges.rs`. 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 d1620a6..0b4e21e 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 eab279a..cfe6776 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 7f40452..df5e79e 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 80fef9e..eb49329 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/package-lock.json b/web/package-lock.json index b4ea69f..a292a4d 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -8,7 +8,7 @@ "name": "sourcejump-web", "version": "0.1.0", "dependencies": { - "flag-icons": "7.6.0", + "country-flag-icons": "1.6.20", "gl-matrix": "3.4.4", "lucide-react": "1.67.0", "lzma1": "0.7.0", @@ -3394,6 +3394,12 @@ "dev": true, "license": "MIT" }, + "node_modules/country-flag-icons": { + "version": "1.6.20", + "resolved": "https://registry.npmjs.org/country-flag-icons/-/country-flag-icons-1.6.20.tgz", + "integrity": "sha512-py8JiEKzjhYw6HPJ0L7SxLgCYim36UPRTZX43/kqGueUCZLSvnrqAiwW8HtQibur7mdkFQUkjOgdK+o/9FBtaw==", + "license": "MIT" + }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", @@ -4364,12 +4370,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/flag-icons": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/flag-icons/-/flag-icons-7.6.0.tgz", - "integrity": "sha512-hir/PsXwr0EESyizKrXJzmkzpLIMf+1vlNKLqAfvdh+bsU94a7LYWTiubkHKqptGoCPzOUGcm6c4PfC9/BaGSQ==", - "license": "MIT" - }, "node_modules/flat-cache": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-4.0.1.tgz", diff --git a/web/package.json b/web/package.json index e3cd268..366916b 100644 --- a/web/package.json +++ b/web/package.json @@ -16,7 +16,7 @@ "test:ui": "playwright test" }, "dependencies": { - "flag-icons": "7.6.0", + "country-flag-icons": "1.6.20", "gl-matrix": "3.4.4", "lucide-react": "1.67.0", "lzma1": "0.7.0", diff --git a/web/src/api/schema.ts b/web/src/api/schema.ts index 87344f9..26fd2fe 100644 --- a/web/src/api/schema.ts +++ b/web/src/api/schema.ts @@ -2266,6 +2266,12 @@ export interface components { /** Format: int64 */ run_id: number; style: string; + /** + * Format: int32 + * @description The board's tier. None while tiers aren't in force or staff haven't set this board's, and for a legacy + * run. + */ + tier?: number | null; /** * Format: double * @description Seconds. @@ -2276,6 +2282,12 @@ export interface components { * @description 0 is the main track, 1 and up are bonuses. */ track: number; + /** + * Format: double + * @description The board's 2.0 record time, as on its map leaderboard, so a client can show the gap to it. None for a + * legacy run. + */ + world_record_time?: number | null; }; PersonalBestPage: { /** @description Pass as `cursor` for the personal bests after these. None at the end. */ @@ -2368,6 +2380,12 @@ export interface components { steamid64: string; /** @description One entry per style they hold a personal best in, sorted by style key. Counts are 2.0 alone. */ styles: components["schemas"]["PlayerStyle"][]; + /** + * Format: int32 + * @description Number of tiers in force; None while the community hasn't set tiers, and personal bests then have no + * tier. + */ + tier_count?: number | null; }; /** * @description A player as leaderboards, records and runs show them: enough to draw their name, avatar and flag, and to diff --git a/web/src/app/activity/page.tsx b/web/src/app/activity/page.tsx index df4720b..4f3fd7e 100644 --- a/web/src/app/activity/page.tsx +++ b/web/src/app/activity/page.tsx @@ -13,7 +13,7 @@ export const metadata: Metadata = { export default function ActivityPage({ searchParams }: PageProps<"/activity">) { return ( -
+
{searchParams.then(({ style, track, tier, show, page }) => (
- - - + + - +
diff --git a/web/src/app/maps/[map]/layout.tsx b/web/src/app/maps/[map]/layout.tsx index e5ba9bf..432becd 100644 --- a/web/src/app/maps/[map]/layout.tsx +++ b/web/src/app/maps/[map]/layout.tsx @@ -7,7 +7,7 @@ export default function MapLayout({ children, }: LayoutProps<"/maps/[map]">) { return ( - + {params.then(({ map }) => ( ))} diff --git a/web/src/app/maps/page.tsx b/web/src/app/maps/page.tsx index cde80b7..851e7bb 100644 --- a/web/src/app/maps/page.tsx +++ b/web/src/app/maps/page.tsx @@ -1,4 +1,5 @@ -// Maps page: every map with a finished run, searchable, with its world record in a chosen style. +// 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. import type { Metadata } from "next"; import { MapList } from "@/features/maps/MapList"; import { Page } from "@/ui/Page"; @@ -10,8 +11,7 @@ export const metadata: Metadata = { export default function MapsPage({ searchParams }: PageProps<"/maps">) { return ( - -

Maps

+ {searchParams.then((params) => ( ))} diff --git a/web/src/app/players/[steamid]/page.tsx b/web/src/app/players/[steamid]/page.tsx index f29f57d..7996c7d 100644 --- a/web/src/app/players/[steamid]/page.tsx +++ b/web/src/app/players/[steamid]/page.tsx @@ -10,7 +10,7 @@ export default function PlayerPage({ params, }: PageProps<"/players/[steamid]">) { return ( - + {params.then(({ steamid }) => ( ))} diff --git a/web/src/app/servers/page.tsx b/web/src/app/servers/page.tsx index 6062a33..cf8ea10 100644 --- a/web/src/app/servers/page.tsx +++ b/web/src/app/servers/page.tsx @@ -11,8 +11,7 @@ export const metadata: Metadata = { export default function ServersPage() { return ( - {/* The board shows this as its own heading from sm up; a phone keeps the two boards apart, so it needs one here. */} -

Servers

+ {/* The board's activity card carries the page's heading, on a phone as on wider screens. */}
); diff --git a/web/src/features/activity/RecentRunTable.tsx b/web/src/features/activity/RecentRunTable.tsx index 3edcd8f..5d2ffae 100644 --- a/web/src/features/activity/RecentRunTable.tsx +++ b/web/src/features/activity/RecentRunTable.tsx @@ -13,13 +13,9 @@ import { } from "react"; import { api, type Schemas } from "@/api/client"; import { ReplayLink } from "@/features/replays/ReplayLink"; +import { RecordGap } from "@/features/runs/RecordGap"; import { RunLink } from "@/features/runs/RunLink"; -import { - formatAge, - formatGap, - formatTime, - trackName, -} from "@/features/runs/time"; +import { formatAge, formatTime, trackName } from "@/features/runs/time"; import { Avatar } from "@/ui/Avatar"; import { Badge } from "@/ui/Badge"; import { classNames } from "@/ui/classNames"; @@ -263,7 +259,88 @@ export function RecentRunTable({ waiting && "opacity-60", )} > - + {/* On a phone each run is two lines, paired by width as ok-website's feed does: the player beside the time + and its gap, the map (the longest part) beside the age (the shortest); the place leads, the replay + ends. Wider screens get the table. */} +
+ # + Player + Time + {/* The replay button's width, so Time sits over the times. */} + +
+
    + {shown.map((run, row) => ( +
  1. +
    + + + +
    +
    + + + {run.player.name} + + {run.player.country_code && ( + + )} + + + + {formatTime(run.time)} + + {run.gap != null && ( + + )} + +
    +
    + {/* One line tall: what doesn't fit wraps below and is hidden, so the style shows whole or not at all. */} + + + + {/* Counted from now, which differs between the server's render and the browser's. */} + +
    +
    + +
    +
  2. + ))} +
+
Player @@ -275,7 +352,8 @@ export function RecentRunTable({ Replay - + {/* Centered, as the column holds marks of different widths: the WR badge, a medal, a number. */} + Place @@ -293,7 +371,7 @@ export function RecentRunTable({ } > - + - {run.tier != null && tierCount != null && ( - - )} - - {run.map} - - {(run.track > 0 || showStyle) && ( - - {[ - run.track > 0 && trackName(run.track), - showStyle && (styleNames[run.style] ?? run.style), - ] - .filter(Boolean) - .join(" · ")} - - )} + @@ -339,20 +410,7 @@ export function RecentRunTable({ {/* Against the record when the run finished: what a new WR took off, or how far behind it was. */} {run.gap != null && ( - 0 - ? "text-danger" - : "text-text-subtle", - )} - > - {run.gap < 0 - ? `(−${formatTime(-run.gap)})` - : `(${formatGap(run.gap)})`} - + )} {/* Counted from now, which differs between the server's render and the browser's. */} @@ -368,16 +426,10 @@ export function RecentRunTable({ - - {run.world_record ? ( - WR - ) : run.placement != null ? ( - - - - ) : ( - – - )} + + + + ))} @@ -429,3 +481,45 @@ function runsIn(loaded: RunChunks): number { function pagesIn(loaded: RunChunks, pageSize: number): number { return Math.max(1, Math.ceil((loaded.total ?? runsIn(loaded)) / pageSize)); } + +/** Where a run was set: the board's tier, the map, and its track and style when they need saying. */ +function RunMap({ + run, + tierCount, + styleName, +}: { + run: Schemas["RecentRun"]; + tierCount: number | null; + /** Left out when the board already shows one style. */ + styleName: string | undefined; +}) { + const extra = [run.track > 0 && trackName(run.track), styleName] + .filter(Boolean) + .join(" · "); + // The tier and map are one piece, shortened only when they alone overrun the line; the track and style follow + // it, and in a line that can't hold them they wrap out of sight (the phone list's line hides its overflow). + return ( + <> + + {run.tier != null && tierCount != null && ( + + )} + + {run.map} + + + {extra && {extra}} + + ); +} + +/** Where a run placed on its board when it finished: the WR badge, a medal or number, or a dash. */ +function Placement({ run }: { run: Schemas["RecentRun"] }) { + if (run.world_record) return WR; + if (run.placement != null) return ; + return –; +} diff --git a/web/src/features/activity/RecentRuns.tsx b/web/src/features/activity/RecentRuns.tsx index 012b530..f13a331 100644 --- a/web/src/features/activity/RecentRuns.tsx +++ b/web/src/features/activity/RecentRuns.tsx @@ -87,7 +87,8 @@ export async function RecentRuns({ params }: { params: RecentRunsParams }) {
Show} options={[ { value: "all", @@ -128,7 +129,12 @@ export async function RecentRuns({ params }: { params: RecentRunsParams }) { {/* Tiers are the community's to set; until a tier count is published there's nothing to filter by. */} {tierCount != null && ( + Tier + Lowest tier + + } options={[ { value: "", label: "Any", href: href({ tier: undefined }) }, ...Array.from({ length: tierCount }, (_, i) => ({ diff --git a/web/src/features/dailyTotals/DailyTotalsChart.tsx b/web/src/features/dailyTotals/DailyTotalsChart.tsx index bde99b4..b7eea5b 100644 --- a/web/src/features/dailyTotals/DailyTotalsChart.tsx +++ b/web/src/features/dailyTotals/DailyTotalsChart.tsx @@ -85,7 +85,7 @@ export function DailyTotalsChart({ const stats = shown && (

{data.kind === "players" ? ( @@ -103,10 +103,8 @@ export function DailyTotalsChart({ )} - - - {when(shown.day, bucketDays)} - + + {when(shown.day, bucketDays)}

); @@ -156,15 +154,17 @@ export function DailyTotalsChart({ const frame = ( <> + {/* On a phone: the title and the range on one line, the totals on the next, so the board starts sooner. + The title's column dissolves there (`contents`) so its two parts can take those places. */}
{heading ? ( -
-

{heading}

+
+

{heading}

{stats}
) : ( @@ -172,7 +172,7 @@ export function DailyTotalsChart({ )} { diff --git a/web/src/features/home/HomeHeader.tsx b/web/src/features/home/HomeHeader.tsx index 7f6dd9f..fd0d610 100644 --- a/web/src/features/home/HomeHeader.tsx +++ b/web/src/features/home/HomeHeader.tsx @@ -21,7 +21,7 @@ const nativePlacement = { /** A static import, so Next.js knows the size, serves modern formats at the screen's width, and blurs in. */ export function HomeHeader() { return ( -
+
{/* On a phone the text takes the lower half, so the picture fills only the top two thirds and fades out there: the jumper then sits between the top edge and the text instead of behind it. The settle zoom is on this box so the depth canvas moves with the picture. */} diff --git a/web/src/features/home/LiveNow.tsx b/web/src/features/home/LiveNow.tsx index d49b268..f031dfb 100644 --- a/web/src/features/home/LiveNow.tsx +++ b/web/src/features/home/LiveNow.tsx @@ -4,6 +4,7 @@ import type { CSSProperties, ReactNode } from "react"; import { api, type Schemas } from "@/api/client"; import { currentStyles } from "@/features/ruleset/styles"; +import { RecordGap } from "@/features/runs/RecordGap"; import { RunLink } from "@/features/runs/RunLink"; import { ReplayLink } from "@/features/replays/ReplayLink"; import { @@ -23,6 +24,12 @@ import { Medal } from "@/ui/Medal"; import { TierBadge } from "@/ui/TierBadge"; const RECORDS = 8; +/** + * Records fetched to find RECORDS boards among: a board's record often falls several times in a row, and only the + * latest shows. shortcut: fewer than RECORDS show if the last 100 records were set on fewer boards; a `distinct` + * option on the API would end that. + */ +const RECORDS_SCANNED = 100; const LEADERS = 10; const SERVERS = 4; const numbers = new Intl.NumberFormat("en"); @@ -31,7 +38,9 @@ export async function LiveNow() { // Each part shows what it has; one that can't be loaded says so, or (the strip) leaves its number out. const [records, servers, leaders, runs, styles] = await Promise.all([ api - .GET("/v1/runs", { params: { query: { records: true, limit: RECORDS } } }) + .GET("/v1/runs", { + params: { query: { records: true, limit: RECORDS_SCANNED } }, + }) .catch(() => undefined), api.GET("/v1/servers").catch(() => undefined), api @@ -86,7 +95,7 @@ export async function LiveNow() { > {records?.data ? ( 1 ? styles.name : undefined} /> @@ -165,7 +174,7 @@ function Pulse({ return (
{shown.map((cell) => ( @@ -276,16 +285,18 @@ function Records({ src={run.player.avatar_url ?? undefined} size="sm" /> - - {run.player.name} - {/* Most players have no country on Steam; a placeholder on every row would only be noise. */} - {run.player.country_code && ( - - )} + + + {run.player.name} + + {run.player.country_code && ( + + )} + {(run.track > 0 || styleName) && ( {[ @@ -309,9 +320,7 @@ function Records({ {formatTime(run.time)} {run.gap != null && run.gap < 0 && ( - - (−{formatTime(-run.gap)}) - + )} {/* Counted from now, which differs between the server's render and the browser's. */} @@ -344,18 +353,21 @@ function Leaders({ standings }: { standings: Schemas["Standing"][] }) { href={`/players/${standing.player.steamid64}`} className="group hover:bg-surface-raised flex h-14 items-center gap-3 px-5 transition-colors duration-(--duration-fast) focus-visible:-outline-offset-2" > - + {/* Counted down the list, not the shared rank of a tie, as on the Leaderboards page. */} + - - {standing.player.name} + + + {standing.player.name} + + {standing.player.country_code && ( + + )} - {standing.player.country_code && ( - - )} {numbers.format(standing.points)} @@ -370,3 +382,14 @@ function Leaders({ standings }: { standings: Schemas["Standing"][] }) { ); } + +/** Each board's latest record only, newest first: one map's record falling seven times reads as seven maps' news. */ +function latestPerBoard(runs: Schemas["RecentRun"][]): Schemas["RecentRun"][] { + const seen = new Set(); + return runs.filter((run) => { + const board = `${run.map}/${run.style}/${run.track}`; + if (seen.has(board)) return false; + seen.add(board); + return true; + }); +} diff --git a/web/src/features/leaderboards/BoardChoices.tsx b/web/src/features/leaderboards/BoardChoices.tsx index 05861a8..7df8f4b 100644 --- a/web/src/features/leaderboards/BoardChoices.tsx +++ b/web/src/features/leaderboards/BoardChoices.tsx @@ -7,14 +7,18 @@ import { ChoiceMenu } from "@/ui/ChoiceMenu"; import { LinkTabs } from "@/ui/LinkTabs"; export type Track = Schemas["LeaderboardTrack"]; -/** Players per page of a full list. */ -export const LIST_PAGE_SIZE = 50; /** - * Players per page of each list on the overview, and per request: five pages, turned in the browser. Here and - * not in StandingsPanel, a client module, whose exports reach server code only as references. + * Players per page: 15 on a full list (a screen's worth), 20 on each of the overview's two lists. Either turns + * pages in the browser, from chunks of players loaded a request at a time (`useStandingsPages`). Here and not in + * a client module, whose exports reach server code only as references. */ +export const LIST_PAGE_SIZE = 15; export const OVERVIEW_PAGE_SIZE = 20; -export const OVERVIEW_CHUNK = 100; +/** + * A multiple of both page sizes, so every page lies within one chunk: with 100, page 7 of 15 (players 91 to 105) + * spanned two chunks and showed only the first one's ten. + */ +export const STANDINGS_CHUNK = 60; type Styles = Awaited>; export interface BoardParams { diff --git a/web/src/features/leaderboards/LeaderboardList.tsx b/web/src/features/leaderboards/LeaderboardList.tsx index 94cc2a8..2070cb2 100644 --- a/web/src/features/leaderboards/LeaderboardList.tsx +++ b/web/src/features/leaderboards/LeaderboardList.tsx @@ -13,6 +13,7 @@ import { boardQuery, completedLabel, LIST_PAGE_SIZE, + STANDINGS_CHUNK, } from "./BoardChoices"; import { PointsNote } from "./PointsNote"; import { StandingsTable } from "./StandingsTable"; @@ -36,6 +37,8 @@ export async function LeaderboardList({ page?: string; }) { const page = Math.max(1, Math.floor(Number(requested)) || 1); + // The chunk of players the page falls in; the table turns pages within it, and loads the chunks beside it ahead. + const chunk = Math.floor(((page - 1) * LIST_PAGE_SIZE) / STANDINGS_CHUNK); const styles = await currentStyles(); const board = boardFrom(params, styles); const list = await api @@ -44,8 +47,8 @@ export async function LeaderboardList({ path: { ranking }, query: { ...boardApiQuery(board), - limit: LIST_PAGE_SIZE, - offset: (page - 1) * LIST_PAGE_SIZE, + limit: STANDINGS_CHUNK, + offset: chunk * STANDINGS_CHUNK, }, }, }) @@ -77,7 +80,7 @@ export async function LeaderboardList({

This leaderboard couldn't be loaded. Try again in a moment.

) : list.standings.length === 0 ? ( - {page > 1 + {chunk > 0 ? "There's no page this far." : ranking === "points" ? !board.legacy && !list.points.tiers @@ -86,16 +89,17 @@ export async function LeaderboardList({ : "Nobody has finished one yet."} ) : ( + // Keyed by the board, so another choice starts again from what the server sent. { - const search = new URLSearchParams(query); - if (to > 1) search.set("page", String(to)); - const text = search.toString(); - return `/leaderboards/${ranking}${text ? `?${text}` : ""}`; - }} + key={query} + ranking={ranking} + apiQuery={boardApiQuery(board)} + first={list.standings} + firstChunk={chunk} + total={list.total} + outOf={list.out_of} + legacy={list.view === "legacy"} + path={`/leaderboards/${ranking}`} completedLabel={label} /> )} diff --git a/web/src/features/leaderboards/Leaderboards.tsx b/web/src/features/leaderboards/Leaderboards.tsx index de24b98..d72f283 100644 --- a/web/src/features/leaderboards/Leaderboards.tsx +++ b/web/src/features/leaderboards/Leaderboards.tsx @@ -11,7 +11,7 @@ import { boardFrom, boardQuery, completedLabel, - OVERVIEW_CHUNK as CHUNK, + STANDINGS_CHUNK as CHUNK, OVERVIEW_PAGE_SIZE as PAGE_SIZE, } from "./BoardChoices"; import { PointsNote } from "./PointsNote"; @@ -92,7 +92,7 @@ export async function Leaderboards({ ); } -/** The hundred players around the page asked for; undefined when they can't be loaded. */ +/** The chunk of players the page asked for falls in; undefined when it can't be loaded. */ function load(ranking: Ranking, board: Board, chunk: number) { return api .GET("/v1/leaderboards/{ranking}", { diff --git a/web/src/features/leaderboards/StandingsPanel.tsx b/web/src/features/leaderboards/StandingsPanel.tsx index a07dba2..96842e9 100644 --- a/web/src/features/leaderboards/StandingsPanel.tsx +++ b/web/src/features/leaderboards/StandingsPanel.tsx @@ -1,32 +1,18 @@ "use client"; -// One list of the Leaderboards page, a page of 20 at a time, turning without a wait as on the Activity board: -// the server sends the hundred players around the page asked for, pages within them turn here at once, and the -// hundreds either side load ahead, so Next and Previous never wait. The pager's links still work without script. -import { useSearchParams } from "next/navigation"; -import { - type CSSProperties, - type FormEvent, - type MouseEvent, - type ReactNode, - useCallback, - useEffect, - useRef, - useState, -} from "react"; -import { api, type Schemas } from "@/api/client"; +// One list of the Leaderboards page, a page of 20 at a time, turning without a wait (`useStandingsPages`). +import type { CSSProperties, ReactNode } from "react"; +import type { Schemas } from "@/api/client"; import { Avatar } from "@/ui/Avatar"; import { Flag } from "@/ui/Flag"; import { Link } from "@/ui/Link"; import { Medal } from "@/ui/Medal"; import { Pager } from "@/ui/Pager"; -import { OVERVIEW_CHUNK, OVERVIEW_PAGE_SIZE } from "./BoardChoices"; +import { OVERVIEW_PAGE_SIZE as PAGE_SIZE } from "./BoardChoices"; +import { useStandingsPages } from "./useStandingsPages"; type Standing = Schemas["ListedStanding"]; type Ranking = Schemas["Ranking"]; -const PAGE_SIZE = OVERVIEW_PAGE_SIZE; -const CHUNK = OVERVIEW_CHUNK; - const numbers = new Intl.NumberFormat("en"); const percent = new Intl.NumberFormat("en", { style: "percent" }); @@ -63,116 +49,28 @@ export function StandingsPanel({ bonuses: boolean; empty: string; }) { - const params = useSearchParams(); - const asked = Math.max(1, Math.floor(Number(params.get(param))) || 1); - const [chunks, setChunks] = useState>( - first ? { [firstChunk]: first } : {}, - ); - const [failed, setFailed] = useState(false); - /** Set after the first turn: pages turned here appear at once, without the rows' entrance. */ - const [turned, setTurned] = useState(false); - const inFlight = useRef(new Map>()); - /** The chunks loaded so far, read by `load` without waiting for a render. */ - const loaded = useRef(chunks); - - const pageCount = Math.max(1, Math.ceil(total / PAGE_SIZE)); - const page = Math.min(asked, pageCount); - const chunkOf = (p: number) => Math.floor(((p - 1) * PAGE_SIZE) / CHUNK); - - const load = useCallback( - (k: number): Promise => { - if (loaded.current[k]) return Promise.resolve(true); - const pending = inFlight.current.get(k); - if (pending) return pending; - const request = api - .GET("/v1/leaderboards/{ranking}", { - params: { - path: { ranking }, - query: { ...apiQuery, limit: CHUNK, offset: k * CHUNK }, - }, - }) - .then((result) => result.data) - .catch(() => undefined) - .then((list) => { - inFlight.current.delete(k); - if (!list) { - setFailed(true); - return false; - } - setFailed(false); - loaded.current = { ...loaded.current, [k]: list.standings }; - setChunks(loaded.current); - return true; - }); - inFlight.current.set(k, request); - return request; - }, - [ranking, apiQuery], - ); - - // The page shown, and the hundreds either side of it, ready before they're asked for. - const shownChunk = chunkOf(page); - useEffect(() => { - void load(shownChunk).then((ok) => { - if (!ok) return; - if ((shownChunk + 1) * CHUNK < total) void load(shownChunk + 1); - if (shownChunk > 0) void load(shownChunk - 1); - }); - }, [shownChunk, total, load]); - - /** This list's page in the address, keeping the board and the other list's page. */ - const pageHref = useCallback( - (to: number) => { - const search = new URLSearchParams(params.toString()); - if (to > 1) search.set(param, String(to)); - else search.delete(param); - const text = search.toString(); - return text ? `/leaderboards?${text}` : "/leaderboards"; - }, - [params, param], - ); - - const turns = useRef(0); - async function go(target: number) { - const turn = ++turns.current; - const wanted = Math.min(Math.max(1, target), pageCount); - if (!(await load(chunkOf(wanted))) || turn !== turns.current) return; - setTurned(true); - window.history.pushState(null, "", pageHref(wanted)); - } - - function onPagerClick(event: MouseEvent) { - const link = (event.target as HTMLElement).closest("a"); - if ( - !link || - event.button !== 0 || - event.metaKey || - event.ctrlKey || - event.shiftKey || - event.altKey - ) - return; - // Stopped here too, as Next's Link navigates even when the event is already prevented. - event.preventDefault(); - event.stopPropagation(); - void go(Number(new URL(link.href).searchParams.get(param) ?? 1)); - } - - function onPagerSubmit(event: FormEvent) { - event.preventDefault(); - event.stopPropagation(); - const form = event.target as HTMLFormElement; - const typed = Math.floor(Number(new FormData(form).get(param))); - form.reset(); - if (typed >= 1) void go(typed); - } - - const chunk = chunks[shownChunk]; - const start = (page - 1) * PAGE_SIZE - shownChunk * CHUNK; - const shown = chunk?.slice(start, start + PAGE_SIZE); + const { + page, + pageCount, + shown, + failed, + turned, + pageHref, + onPagerClick, + onPagerSubmit, + } = useStandingsPages({ + ranking, + apiQuery, + first, + firstChunk, + total, + pageSize: PAGE_SIZE, + param, + path: "/leaderboards", + }); return ( -
+

{title} @@ -209,7 +107,10 @@ export function StandingsPanel({ } as CSSProperties) } > - + {ranking === "points" ? ( <> @@ -259,9 +160,15 @@ export function StandingsPanel({ function Row({ standing, + place, children, }: { standing: Standing; + /** + * The row's place down the list, counted 1, 2, 3 even where players tie: a column of the same rank repeated + * read as a mistake. Ties keep the API's order. + */ + place: number; children: ReactNode; }) { return ( @@ -269,18 +176,21 @@ function Row({ href={`/players/${standing.player.steamid64}`} className="group hover:bg-surface-raised flex h-14 items-center gap-3 px-5 transition-colors duration-(--duration-fast) focus-visible:-outline-offset-2" > - + - - {standing.player.name} + {/* The flag sits close to the name it belongs to; most players have no country on Steam, and a + placeholder on every row would only be noise. */} + + + {standing.player.name} + + {standing.player.country_code && ( + + )} - {/* Most players have no country on Steam; a placeholder on every row would only be noise. */} - {standing.player.country_code && ( - - )} {children} diff --git a/web/src/features/leaderboards/StandingsTable.tsx b/web/src/features/leaderboards/StandingsTable.tsx index fbdefcb..8e572d2 100644 --- a/web/src/features/leaderboards/StandingsTable.tsx +++ b/web/src/features/leaderboards/StandingsTable.tsx @@ -1,5 +1,6 @@ -// One leaderboard in full, as a table, a page of 50 at a time with page links beneath. Beside each player's points -// and completions, their share of the tracks and their world records. +"use client"; +// One leaderboard in full, as a table, 15 players a page, turning without a wait (`useStandingsPages`). Beside each +// player's points and completions, their share of the tracks and their world records. import type { CSSProperties } from "react"; import type { Schemas } from "@/api/client"; import { Avatar } from "@/ui/Avatar"; @@ -16,53 +17,97 @@ import { TableRow, } from "@/ui/Table"; import { LIST_PAGE_SIZE as PAGE_SIZE } from "./BoardChoices"; +import { useStandingsPages } from "./useStandingsPages"; const numbers = new Intl.NumberFormat("en"); const percent = new Intl.NumberFormat("en", { style: "percent" }); -type List = Schemas["LeaderboardList"]; +type Standing = Schemas["ListedStanding"]; export function StandingsTable({ - list, - page, - href, + ranking, + apiQuery, + first, + firstChunk, + total, + outOf, + legacy, + path, completedLabel, }: { - list: List; - page: number; - /** The address of another page of this board. */ - href: (page: number) => string; + ranking: Schemas["Ranking"]; + /** What the API takes for this board, without the paging. */ + apiQuery: Record; + /** The chunk the page asked for falls in, from the server. */ + first: Standing[]; + firstChunk: number; + total: number; + /** What completions are counted out of. */ + outOf: number; + /** The Pre-2.0 view, which has no world records to count. */ + legacy: boolean; + /** This list's own page, which the address keeps. */ + path: string; /** "Completed maps" or "Completed bonuses". */ completedLabel: string; }) { - const first = list; - const standings = list.standings; - const byPoints = first.ranking === "points"; - const legacy = first.view === "legacy"; + const { + page, + pageCount, + shown, + failed, + turned, + pageHref, + onPagerClick, + onPagerSubmit, + } = useStandingsPages({ + ranking, + apiQuery, + first, + firstChunk, + total, + pageSize: PAGE_SIZE, + param: "page", + path, + }); + const byPoints = ranking === "points"; // The ranked value comes first after the player, the other one after it. - const pointsCell = (standing: Schemas["ListedStanding"]) => ( + const pointsCell = (standing: Standing) => ( {numbers.format(standing.points)} ); - const completedCell = (standing: Schemas["ListedStanding"]) => ( + const completedCell = (standing: Standing) => ( {numbers.format(standing.completed)} - {first.out_of > 0 && ( + {outOf > 0 && ( - {percent.format(standing.completed / first.out_of)} + {percent.format(standing.completed / outOf)} )} ); + if (!shown) { + return ( +

+ {failed + ? "This page couldn't be loaded. Try again in a moment." + : "Loading…"} +

+ ); + } + return (

- Rank + {/* Centered over the medals and numbers, which are narrower than the heading. */} + + Rank + {/* The player column takes the spare width, so the numbers sit together on the right, evenly spaced. */} Player {byPoints ? ( @@ -82,21 +127,27 @@ export function StandingsTable({ - {standings.map((standing, index) => ( + {shown.map((standing, index) => ( - - + + {/* Counted down the list, not the shared rank of a tie, as on the overview (StandingsPanel). */} + + + - +
- + {pageCount > 1 && ( +
+ +
+ )}
); } diff --git a/web/src/features/leaderboards/useStandingsPages.ts b/web/src/features/leaderboards/useStandingsPages.ts new file mode 100644 index 0000000..2bb65b2 --- /dev/null +++ b/web/src/features/leaderboards/useStandingsPages.ts @@ -0,0 +1,174 @@ +// Paging a leaderboard without a wait, as on the Activity board: the server sends the chunk of players the page +// asked for falls in, pages within it turn here at once, and the chunks either side load ahead, so Next and +// Previous never wait. The page lives in the address (pushed, so Back works), and the pager's links and form still +// work without script. Shared by the overview's lists (StandingsPanel) and the full tables (StandingsTable). +import { useSearchParams } from "next/navigation"; +import { + type FormEvent, + type MouseEvent, + useCallback, + useEffect, + useRef, + useState, +} from "react"; +import { api, type Schemas } from "@/api/client"; +import { STANDINGS_CHUNK } from "./BoardChoices"; + +type Standing = Schemas["ListedStanding"]; + +export function useStandingsPages({ + ranking, + apiQuery, + first, + firstChunk, + total, + pageSize, + param, + path, +}: { + ranking: Schemas["Ranking"]; + /** What the API takes for this board, without the paging. */ + apiQuery: Record; + /** The chunk the page asked for falls in, from the server; undefined when it couldn't be loaded. */ + first: Standing[] | undefined; + firstChunk: number; + total: number; + pageSize: number; + /** This list's page in the address. */ + param: string; + /** The page's path, which the address keeps. */ + path: string; +}) { + const params = useSearchParams(); + const asked = Math.max(1, Math.floor(Number(params.get(param))) || 1); + const [chunks, setChunks] = useState>( + first ? { [firstChunk]: first } : {}, + ); + const [failed, setFailed] = useState(false); + /** Set after the first turn: pages turned here appear at once, without the rows' entrance. */ + const [turned, setTurned] = useState(false); + const inFlight = useRef(new Map>()); + /** The chunks loaded so far, read by `load` without waiting for a render. */ + const loaded = useRef(chunks); + + // A page is cut from one chunk, so it has to divide the chunk evenly; else a page spanning two would come up short. + if (STANDINGS_CHUNK % pageSize !== 0) { + throw new Error( + `A page of ${pageSize} doesn't divide a chunk of ${STANDINGS_CHUNK}`, + ); + } + const pageCount = Math.max(1, Math.ceil(total / pageSize)); + const page = Math.min(asked, pageCount); + const chunkOf = useCallback( + (p: number) => Math.floor(((p - 1) * pageSize) / STANDINGS_CHUNK), + [pageSize], + ); + + const load = useCallback( + (k: number): Promise => { + if (loaded.current[k]) return Promise.resolve(true); + const pending = inFlight.current.get(k); + if (pending) return pending; + const request = api + .GET("/v1/leaderboards/{ranking}", { + params: { + path: { ranking }, + query: { + ...apiQuery, + limit: STANDINGS_CHUNK, + offset: k * STANDINGS_CHUNK, + }, + }, + }) + .then((result) => result.data) + .catch(() => undefined) + .then((list) => { + inFlight.current.delete(k); + if (!list) { + setFailed(true); + return false; + } + setFailed(false); + loaded.current = { ...loaded.current, [k]: list.standings }; + setChunks(loaded.current); + return true; + }); + inFlight.current.set(k, request); + return request; + }, + [ranking, apiQuery], + ); + + // The page shown, and the chunks either side of it, ready before they're asked for. + const shownChunk = chunkOf(page); + useEffect(() => { + void load(shownChunk).then((ok) => { + if (!ok) return; + if ((shownChunk + 1) * STANDINGS_CHUNK < total) void load(shownChunk + 1); + if (shownChunk > 0) void load(shownChunk - 1); + }); + }, [shownChunk, total, load]); + + /** This list's page in the address, keeping the board and any other list's page. */ + const pageHref = useCallback( + (to: number) => { + const search = new URLSearchParams(params.toString()); + if (to > 1) search.set(param, String(to)); + else search.delete(param); + const text = search.toString(); + return text ? `${path}?${text}` : path; + }, + [params, param, path], + ); + + const turns = useRef(0); + async function go(target: number) { + const turn = ++turns.current; + const wanted = Math.min(Math.max(1, target), pageCount); + if (!(await load(chunkOf(wanted))) || turn !== turns.current) return; + setTurned(true); + window.history.pushState(null, "", pageHref(wanted)); + } + + /** For the pager's wrapper, in the capture phase: turns pages here instead of loading them. */ + function onPagerClick(event: MouseEvent) { + const link = (event.target as HTMLElement).closest("a"); + if ( + !link || + event.button !== 0 || + event.metaKey || + event.ctrlKey || + event.shiftKey || + event.altKey + ) + return; + // Stopped here too, as Next's Link navigates even when the event is already prevented. + event.preventDefault(); + event.stopPropagation(); + void go(Number(new URL(link.href).searchParams.get(param) ?? 1)); + } + + /** The pager's "go to page" form. */ + function onPagerSubmit(event: FormEvent) { + event.preventDefault(); + event.stopPropagation(); + const form = event.target as HTMLFormElement; + const typed = Math.floor(Number(new FormData(form).get(param))); + form.reset(); + if (typed >= 1) void go(typed); + } + + const chunk = chunks[shownChunk]; + const start = (page - 1) * pageSize - shownChunk * STANDINGS_CHUNK; + return { + page, + pageCount, + /** The page's rows; undefined while they load or when they couldn't be. */ + shown: chunk?.slice(start, start + pageSize), + failed, + turned, + pageHref, + onPagerClick, + onPagerSubmit, + }; +} diff --git a/web/src/features/legacy/LegacyRunDetailList.tsx b/web/src/features/legacy/LegacyRunDetailList.tsx index 51ea88a..1e05138 100644 --- a/web/src/features/legacy/LegacyRunDetailList.tsx +++ b/web/src/features/legacy/LegacyRunDetailList.tsx @@ -54,8 +54,10 @@ export function LegacyRunDetailList({ src={run.player.avatar_url ?? undefined} size="sm" /> - {run.player.name} - + + {run.player.name} + + {run.player_name !== run.player.name && ( diff --git a/web/src/features/maps/Leaderboard.tsx b/web/src/features/maps/Leaderboard.tsx index 42c3fc6..d4cf645 100644 --- a/web/src/features/maps/Leaderboard.tsx +++ b/web/src/features/maps/Leaderboard.tsx @@ -1,19 +1,28 @@ "use client"; // A map's leaderboard for one style, track and view: the 2.0 top comes with the page, other views load their -// first page when chosen, and "Show more" loads the rest a page at a time. The signed-in player's row stands -// out, and legacy runs carry the Pre-2.0 badge. +// first page when chosen, and "Show more" loads the rest a page at a time. Headings sort it: the API orders +// boards by time only, so sorting by anything else loads the whole board and sorts it here. The signed-in +// player's row stands out, and legacy runs carry the Pre-2.0 badge. import { useEffect, useState } from "react"; import { api, type Schemas } from "@/api/client"; import { LegacyBadge } from "@/features/legacy/LegacyBadge"; import type { View } from "@/features/legacy/views"; +import { ReplayLink } from "@/features/replays/ReplayLink"; import { RunLink } from "@/features/runs/RunLink"; -import { formatDate, formatGap, formatTime } from "@/features/runs/time"; +import { + formatAge, + formatDate, + formatGap, + formatTime, +} from "@/features/runs/time"; import { Avatar } from "@/ui/Avatar"; import { Badge } from "@/ui/Badge"; import { Button } from "@/ui/Button"; +import { classNames } from "@/ui/classNames"; import { Flag } from "@/ui/Flag"; import { Link } from "@/ui/Link"; import { Medal } from "@/ui/Medal"; +import { SortButton } from "@/ui/SortButton"; import { Table, TableBody, @@ -24,8 +33,60 @@ import { } from "@/ui/Table"; const PAGE_SIZE = 50; +/** The API's largest page, for loading a whole board to sort. */ +const FULL_PAGE_SIZE = 100; const sync = new Intl.NumberFormat("en", { maximumFractionDigits: 1 }); +type Entry = Schemas["LeaderboardEntry"]; +type SortKey = "time" | "player" | "jumps" | "strafes" | "sync" | "date"; +interface Sort { + key: SortKey; + descending: boolean; +} + +/** Which way a column sorts on its first click: best sync and newest date first, the rest from the smallest. */ +const descendingFirst: Record = { + time: false, + player: false, + jumps: false, + strafes: false, + sync: true, + date: true, +}; + +/** Entries in the chosen order; ties keep the board's order by time. */ +function sorted(entries: Entry[], sort: Sort): Entry[] { + if (sort.key === "time" && !sort.descending) return entries; + const value = (entry: Entry): number | string => { + switch (sort.key) { + case "time": + return entry.time; + case "player": + return entry.player.name.toLowerCase(); + case "jumps": + return entry.jumps; + case "strafes": + return entry.strafes; + case "sync": + return entry.sync; + case "date": + // Runs without a date sort as the oldest. + return entry.finished_at ? Date.parse(entry.finished_at) : 0; + } + }; + const direction = sort.descending ? -1 : 1; + return entries + .map((entry, index) => ({ entry, index, value: value(entry) })) + .sort((a, b) => + a.value < b.value + ? -direction + : a.value > b.value + ? direction + : a.index - b.index, + ) + .map(({ entry }) => entry); +} + /** A page of a board, as the leaderboard endpoint or (for 2.0's top) the map's details give it. */ export type BoardPage = Pick< Schemas["Leaderboard"], @@ -55,6 +116,7 @@ export function Leaderboard({ const [cursor, setCursor] = useState(first?.next_cursor); const [loading, setLoading] = useState(false); const [failed, setFailed] = useState(false); + const [sort, setSort] = useState({ key: "time", descending: false }); // A refreshed page (after a staff change, say) brings a new first page; start again from it. const [shownFrom, setShownFrom] = useState(first); if (first && shownFrom !== first) { @@ -64,12 +126,12 @@ export function Leaderboard({ setCursor(first.next_cursor); } - function fetchPage(after: string | undefined) { + function fetchPage(after: string | undefined, limit = PAGE_SIZE) { return api .GET("/v1/maps/{map}/leaderboard", { params: { path: { map }, - query: { style, track, view, limit: PAGE_SIZE, cursor: after }, + query: { style, track, view, limit, cursor: after }, }, }) .then((result) => result.data) @@ -96,6 +158,39 @@ export function Leaderboard({ show(loaded, after); } + /** + * Sorts by a column: again on the same one turns it around. Any order but time's needs the whole board. + * shortcut: loads every row in the browser, 100 a request; fine for boards of a few hundred players, ask the API + * for a `sort` parameter when boards grow to thousands. + */ + async function sortBy(key: SortKey) { + const next: Sort = + sort.key === key + ? { key, descending: !sort.descending } + : { key, descending: descendingFirst[key] }; + if (key !== "time" && cursor) { + setLoading(true); + setFailed(false); + let all = entries; + let after: string | null | undefined = cursor; + while (after) { + const loaded = await fetchPage(after, FULL_PAGE_SIZE); + if (!loaded) { + setLoading(false); + setFailed(true); + return; + } + all = [...all, ...loaded.entries]; + after = loaded.next_cursor; + setPage(loaded); + } + setEntries(all); + setCursor(undefined); + setLoading(false); + } + setSort(next); + } + // Views other than 2.0's don't come with the map; their first page loads once the view is chosen. useEffect(() => { if (!first) @@ -112,59 +207,161 @@ export function Leaderboard({ } const fastest = page.fastest_time; const record = page.world_record_time; + const heading = (key: SortKey, label: string) => ( + void sortBy(key)} + /> + ); + const ariaSort = (key: SortKey) => + sort.key === key + ? sort.descending + ? ("descending" as const) + : ("ascending" as const) + : undefined; return (
- +
- Place - Player - Time - Gap - Jumps - Strafes - Sync - Date + {/* Short columns center under their names: a medal, a WR badge and a few digits are all narrower than + the heading, and right-aligned they sat off to one side of it. Times and dates keep to the right. + Place and Gap follow the time, so Time sorts for them. */} + + Place + + + {heading("player", "Player")} + + + {heading("time", "Time")} + + {/* Narrow padding keeps the play button close to the time, as on Activity. */} + + Replay + + {/* On a phone the gap and age go under the time instead, and these columns step aside. */} + + Gap + + + {heading("jumps", "Jumps")} + + + {heading("strafes", "Strafes")} + + + {heading("sync", "Sync")} + + + {heading("date", "Date")} + - {entries.map((entry) => ( + {sorted(entries, sort).map((entry) => ( - + {/* Medals mark 2.0 standings; the other views are lists by time. */} - + + + - - + {/* On a phone the player column takes only the room left (`max-w-0` with full width), and a long + name ends in an ellipsis rather than pushing the times off the screen. */} + + - {entry.player.name} + {entry.player.name} - + {/* A missing country's placeholder costs a phone's narrow column more than it tells. */} + {entry.legacy && } - - - {formatTime(entry.time)} - + + + + + {formatTime(entry.time)} + + {/* On a phone, the Gap column's content, as on the Activity board. */} + + {!entry.legacy && entry.time === record ? ( + WR + ) : entry.time === fastest || fastest == null ? null : ( + + ({formatGap(entry.time - fastest)}) + + )} + + + {entry.finished_at && ( + // Counted from now, which differs between the server's render and the browser's. + + )} + + + + {/* Replays open by 2.0 run ID; a pre-2.0 run's ID is the old site's. */} + {!entry.legacy && } - + {!entry.legacy && entry.time === record ? ( WR ) : entry.time === fastest || fastest == null ? null : ( @@ -173,16 +370,16 @@ export function Leaderboard({ )} - + {entry.jumps} - + {entry.strafes} - + {sync.format(entry.sync)}% - + {entry.finished_at ? (
+
- Place - Map - {!style && Style} - Time - Date + {/* As on a map's board: Place centered over its medals, the play button close beside the time. On a + phone the style goes under the map, the gap beside the time and the date becomes an age under it, + so the row fits without scrolling. */} + + {heading("place", "Place")} + + + {heading("map", "Map")} + + {!style && ( + + {heading("style", "Style")} + + )} + + {heading("time", "Time")} + + + Replay + + + {heading("gap", "Gap")} + + + {heading("date", "Date")} + - {personalBests.map((pb, index) => ( + {rows.map((pb, index) => ( - + {/* A legacy run has no 2.0 placement. */} - {pb.rank == null ? ( - - – - - ) : ( - - )} + + {pb.rank == null ? ( + + – + + ) : ( + + )} + - - + + + {pb.tier != null && tierCount != null && ( + + )} 0 ? `&track=${pb.track}` : ""}` } - className="hover:text-accent" + title={pb.map} + className="hover:text-accent truncate" > {pb.map} @@ -524,26 +673,54 @@ function PersonalBests({ {pb.rank === 1 && WR} {pb.legacy && } + {!style && ( + + {styleName(pb.style)} + + )} {!style && ( - + {styleName(pb.style)} )} - - {/* Legacy runs have no run page: the old site kept no more than this row. */} - {pb.legacy ? ( - formatTime(pb.time) - ) : ( - - {formatTime(pb.time)} - - )} + + + + {/* Legacy runs have no run page: the old site kept no more than this row. */} + {pb.legacy ? ( + formatTime(pb.time) + ) : ( + + {formatTime(pb.time)} + + )} + {/* On a phone, the Gap column's content, as on a map's board. */} + + + {pb.finished_at && ( + // Counted from now, which differs between the server's render and the browser's. + + )} + + + + {/* Replays open by 2.0 run ID; a pre-2.0 run's ID is the old site's. */} + {!pb.legacy && } + + + - + {pb.finished_at ? (
T{tier} diff --git a/web/src/ui/TierSpread.tsx b/web/src/ui/TierSpread.tsx index abd9759..ff56bd3 100644 --- a/web/src/ui/TierSpread.tsx +++ b/web/src/ui/TierSpread.tsx @@ -1,6 +1,7 @@ // 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. +// 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. import type { CSSProperties } from "react"; import { classNames } from "./classNames"; import { Link } from "./Link"; @@ -76,126 +77,205 @@ export function TierSpread({ ); return ( -
- - {untiered > 0 && ( - - )} - {slices.map( - ({ tier, count, start, length }) => - count > 0 && ( - - {`Tier ${tier}: ${number.format(count)} maps`} - +
+ {/* The donut's shares laid end to end. */} +
+ {slices.map( + ({ tier, count }) => + count > 0 && ( + - - ), - )} - {/* Counter-rotated, so the middle reads upright inside the turned ring. */} - - - {selected != null ? `T${selected}` : "All"} - - {chosen != null && ( - - {number.format(chosen)} maps - + ), )} - - - - {/* "All", always there to go back to, heads the first column and "No tier" the second; the tiers split - evenly below them, low tiers first. One column on phones, with "No tier" last. */} -
    -
  • + {untiered > 0 && } +
+
- All - - {number.format(total - untiered)} + All tiers + + {number.format(total - untiered)} maps - - {slices.slice(0, half).map(tierRow)} - {untiered > 0 ? ( -
  • - No tier - - {number.format(untiered)} - - - {percent.format(untiered / total)} + {untiered > 0 && ( + + {number.format(untiered)} without a tier + )} +
  • +
      + {slices.map(({ tier, count }) => ( +
    • + + + + {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", always there to go back to, heads the first column and "No tier" the second; the tiers split + evenly below them, low tiers first. One column on phones, with "No tier" last. */} +
      + {/* One cell across the row, the count just after the word: it's the list's total, not a tier's. Chosen, + it takes the accent, as nothing else dims to show it. */} +
    • + + All tiers + + {number.format(total - untiered)} maps + +
    • - ) : ( -
    • - )} - {slices.slice(half).map(tierRow)} -
    -
    + {slices.slice(0, half).map(tierRow)} + {untiered > 0 ? ( +
  • + No tier + + {number.format(untiered)} + + + {percent.format(untiered / total)} + +
  • + ) : ( +
  • + )} + {slices.slice(half).map(tierRow)} + +
  • + ); } diff --git a/web/src/ui/flags.css b/web/src/ui/flags.css new file mode 100644 index 0000000..8fe5899 --- /dev/null +++ b/web/src/ui/flags.css @@ -0,0 +1,798 @@ +/* One class per country, each pointing at its own 3:2 flag from country-flag-icons, so a browser downloads only + the flags it shows (the package's own flags.css inlines every one). Made from the package's 3x2 folder: + ls node_modules/country-flag-icons/3x2/*.svg; redo it when the package adds a country. */ +.flag-ac { + background-image: url("../../node_modules/country-flag-icons/3x2/AC.svg"); +} +.flag-ad { + background-image: url("../../node_modules/country-flag-icons/3x2/AD.svg"); +} +.flag-ae { + background-image: url("../../node_modules/country-flag-icons/3x2/AE.svg"); +} +.flag-af { + background-image: url("../../node_modules/country-flag-icons/3x2/AF.svg"); +} +.flag-ag { + background-image: url("../../node_modules/country-flag-icons/3x2/AG.svg"); +} +.flag-ai { + background-image: url("../../node_modules/country-flag-icons/3x2/AI.svg"); +} +.flag-al { + background-image: url("../../node_modules/country-flag-icons/3x2/AL.svg"); +} +.flag-am { + background-image: url("../../node_modules/country-flag-icons/3x2/AM.svg"); +} +.flag-ao { + background-image: url("../../node_modules/country-flag-icons/3x2/AO.svg"); +} +.flag-aq { + background-image: url("../../node_modules/country-flag-icons/3x2/AQ.svg"); +} +.flag-ar { + background-image: url("../../node_modules/country-flag-icons/3x2/AR.svg"); +} +.flag-as { + background-image: url("../../node_modules/country-flag-icons/3x2/AS.svg"); +} +.flag-at { + background-image: url("../../node_modules/country-flag-icons/3x2/AT.svg"); +} +.flag-au { + background-image: url("../../node_modules/country-flag-icons/3x2/AU.svg"); +} +.flag-aw { + background-image: url("../../node_modules/country-flag-icons/3x2/AW.svg"); +} +.flag-ax { + background-image: url("../../node_modules/country-flag-icons/3x2/AX.svg"); +} +.flag-az { + background-image: url("../../node_modules/country-flag-icons/3x2/AZ.svg"); +} +.flag-ba { + background-image: url("../../node_modules/country-flag-icons/3x2/BA.svg"); +} +.flag-bb { + background-image: url("../../node_modules/country-flag-icons/3x2/BB.svg"); +} +.flag-bd { + background-image: url("../../node_modules/country-flag-icons/3x2/BD.svg"); +} +.flag-be { + background-image: url("../../node_modules/country-flag-icons/3x2/BE.svg"); +} +.flag-bf { + background-image: url("../../node_modules/country-flag-icons/3x2/BF.svg"); +} +.flag-bg { + background-image: url("../../node_modules/country-flag-icons/3x2/BG.svg"); +} +.flag-bh { + background-image: url("../../node_modules/country-flag-icons/3x2/BH.svg"); +} +.flag-bi { + background-image: url("../../node_modules/country-flag-icons/3x2/BI.svg"); +} +.flag-bj { + background-image: url("../../node_modules/country-flag-icons/3x2/BJ.svg"); +} +.flag-bl { + background-image: url("../../node_modules/country-flag-icons/3x2/BL.svg"); +} +.flag-bm { + background-image: url("../../node_modules/country-flag-icons/3x2/BM.svg"); +} +.flag-bn { + background-image: url("../../node_modules/country-flag-icons/3x2/BN.svg"); +} +.flag-bo { + background-image: url("../../node_modules/country-flag-icons/3x2/BO.svg"); +} +.flag-bq-bo { + background-image: url("../../node_modules/country-flag-icons/3x2/BQ-BO.svg"); +} +.flag-bq-sa { + background-image: url("../../node_modules/country-flag-icons/3x2/BQ-SA.svg"); +} +.flag-bq-se { + background-image: url("../../node_modules/country-flag-icons/3x2/BQ-SE.svg"); +} +.flag-bq { + background-image: url("../../node_modules/country-flag-icons/3x2/BQ.svg"); +} +.flag-br { + background-image: url("../../node_modules/country-flag-icons/3x2/BR.svg"); +} +.flag-bs { + background-image: url("../../node_modules/country-flag-icons/3x2/BS.svg"); +} +.flag-bt { + background-image: url("../../node_modules/country-flag-icons/3x2/BT.svg"); +} +.flag-bv { + background-image: url("../../node_modules/country-flag-icons/3x2/BV.svg"); +} +.flag-bw { + background-image: url("../../node_modules/country-flag-icons/3x2/BW.svg"); +} +.flag-by { + background-image: url("../../node_modules/country-flag-icons/3x2/BY.svg"); +} +.flag-bz { + background-image: url("../../node_modules/country-flag-icons/3x2/BZ.svg"); +} +.flag-ca { + background-image: url("../../node_modules/country-flag-icons/3x2/CA.svg"); +} +.flag-cc { + background-image: url("../../node_modules/country-flag-icons/3x2/CC.svg"); +} +.flag-cd { + background-image: url("../../node_modules/country-flag-icons/3x2/CD.svg"); +} +.flag-cf { + background-image: url("../../node_modules/country-flag-icons/3x2/CF.svg"); +} +.flag-cg { + background-image: url("../../node_modules/country-flag-icons/3x2/CG.svg"); +} +.flag-ch { + background-image: url("../../node_modules/country-flag-icons/3x2/CH.svg"); +} +.flag-ci { + background-image: url("../../node_modules/country-flag-icons/3x2/CI.svg"); +} +.flag-ck { + background-image: url("../../node_modules/country-flag-icons/3x2/CK.svg"); +} +.flag-cl { + background-image: url("../../node_modules/country-flag-icons/3x2/CL.svg"); +} +.flag-cm { + background-image: url("../../node_modules/country-flag-icons/3x2/CM.svg"); +} +.flag-cn { + background-image: url("../../node_modules/country-flag-icons/3x2/CN.svg"); +} +.flag-co { + background-image: url("../../node_modules/country-flag-icons/3x2/CO.svg"); +} +.flag-cr { + background-image: url("../../node_modules/country-flag-icons/3x2/CR.svg"); +} +.flag-cu { + background-image: url("../../node_modules/country-flag-icons/3x2/CU.svg"); +} +.flag-cv { + background-image: url("../../node_modules/country-flag-icons/3x2/CV.svg"); +} +.flag-cw { + background-image: url("../../node_modules/country-flag-icons/3x2/CW.svg"); +} +.flag-cx { + background-image: url("../../node_modules/country-flag-icons/3x2/CX.svg"); +} +.flag-cy { + background-image: url("../../node_modules/country-flag-icons/3x2/CY.svg"); +} +.flag-cz { + background-image: url("../../node_modules/country-flag-icons/3x2/CZ.svg"); +} +.flag-de { + background-image: url("../../node_modules/country-flag-icons/3x2/DE.svg"); +} +.flag-dj { + background-image: url("../../node_modules/country-flag-icons/3x2/DJ.svg"); +} +.flag-dk { + background-image: url("../../node_modules/country-flag-icons/3x2/DK.svg"); +} +.flag-dm { + background-image: url("../../node_modules/country-flag-icons/3x2/DM.svg"); +} +.flag-do { + background-image: url("../../node_modules/country-flag-icons/3x2/DO.svg"); +} +.flag-dz { + background-image: url("../../node_modules/country-flag-icons/3x2/DZ.svg"); +} +.flag-ec { + background-image: url("../../node_modules/country-flag-icons/3x2/EC.svg"); +} +.flag-ee { + background-image: url("../../node_modules/country-flag-icons/3x2/EE.svg"); +} +.flag-eg { + background-image: url("../../node_modules/country-flag-icons/3x2/EG.svg"); +} +.flag-eh { + background-image: url("../../node_modules/country-flag-icons/3x2/EH.svg"); +} +.flag-er { + background-image: url("../../node_modules/country-flag-icons/3x2/ER.svg"); +} +.flag-es-ct { + background-image: url("../../node_modules/country-flag-icons/3x2/ES-CT.svg"); +} +.flag-es { + background-image: url("../../node_modules/country-flag-icons/3x2/ES.svg"); +} +.flag-et { + background-image: url("../../node_modules/country-flag-icons/3x2/ET.svg"); +} +.flag-eu { + background-image: url("../../node_modules/country-flag-icons/3x2/EU.svg"); +} +.flag-fi { + background-image: url("../../node_modules/country-flag-icons/3x2/FI.svg"); +} +.flag-fj { + background-image: url("../../node_modules/country-flag-icons/3x2/FJ.svg"); +} +.flag-fk { + background-image: url("../../node_modules/country-flag-icons/3x2/FK.svg"); +} +.flag-fm { + background-image: url("../../node_modules/country-flag-icons/3x2/FM.svg"); +} +.flag-fo { + background-image: url("../../node_modules/country-flag-icons/3x2/FO.svg"); +} +.flag-fr { + background-image: url("../../node_modules/country-flag-icons/3x2/FR.svg"); +} +.flag-ga { + background-image: url("../../node_modules/country-flag-icons/3x2/GA.svg"); +} +.flag-gb-eng { + background-image: url("../../node_modules/country-flag-icons/3x2/GB-ENG.svg"); +} +.flag-gb-nir { + background-image: url("../../node_modules/country-flag-icons/3x2/GB-NIR.svg"); +} +.flag-gb-sct { + background-image: url("../../node_modules/country-flag-icons/3x2/GB-SCT.svg"); +} +.flag-gb { + background-image: url("../../node_modules/country-flag-icons/3x2/GB.svg"); +} +.flag-gb-wls { + background-image: url("../../node_modules/country-flag-icons/3x2/GB-WLS.svg"); +} +.flag-gd { + background-image: url("../../node_modules/country-flag-icons/3x2/GD.svg"); +} +.flag-ge { + background-image: url("../../node_modules/country-flag-icons/3x2/GE.svg"); +} +.flag-gf { + background-image: url("../../node_modules/country-flag-icons/3x2/GF.svg"); +} +.flag-gg { + background-image: url("../../node_modules/country-flag-icons/3x2/GG.svg"); +} +.flag-gh { + background-image: url("../../node_modules/country-flag-icons/3x2/GH.svg"); +} +.flag-gi { + background-image: url("../../node_modules/country-flag-icons/3x2/GI.svg"); +} +.flag-gl { + background-image: url("../../node_modules/country-flag-icons/3x2/GL.svg"); +} +.flag-gm { + background-image: url("../../node_modules/country-flag-icons/3x2/GM.svg"); +} +.flag-gn { + background-image: url("../../node_modules/country-flag-icons/3x2/GN.svg"); +} +.flag-gp { + background-image: url("../../node_modules/country-flag-icons/3x2/GP.svg"); +} +.flag-gq { + background-image: url("../../node_modules/country-flag-icons/3x2/GQ.svg"); +} +.flag-gr { + background-image: url("../../node_modules/country-flag-icons/3x2/GR.svg"); +} +.flag-gs { + background-image: url("../../node_modules/country-flag-icons/3x2/GS.svg"); +} +.flag-gt { + background-image: url("../../node_modules/country-flag-icons/3x2/GT.svg"); +} +.flag-gu { + background-image: url("../../node_modules/country-flag-icons/3x2/GU.svg"); +} +.flag-gw { + background-image: url("../../node_modules/country-flag-icons/3x2/GW.svg"); +} +.flag-gy { + background-image: url("../../node_modules/country-flag-icons/3x2/GY.svg"); +} +.flag-hk { + background-image: url("../../node_modules/country-flag-icons/3x2/HK.svg"); +} +.flag-hm { + background-image: url("../../node_modules/country-flag-icons/3x2/HM.svg"); +} +.flag-hn { + background-image: url("../../node_modules/country-flag-icons/3x2/HN.svg"); +} +.flag-hr { + background-image: url("../../node_modules/country-flag-icons/3x2/HR.svg"); +} +.flag-ht { + background-image: url("../../node_modules/country-flag-icons/3x2/HT.svg"); +} +.flag-hu { + background-image: url("../../node_modules/country-flag-icons/3x2/HU.svg"); +} +.flag-ic { + background-image: url("../../node_modules/country-flag-icons/3x2/IC.svg"); +} +.flag-id { + background-image: url("../../node_modules/country-flag-icons/3x2/ID.svg"); +} +.flag-ie { + background-image: url("../../node_modules/country-flag-icons/3x2/IE.svg"); +} +.flag-il { + background-image: url("../../node_modules/country-flag-icons/3x2/IL.svg"); +} +.flag-im { + background-image: url("../../node_modules/country-flag-icons/3x2/IM.svg"); +} +.flag-in { + background-image: url("../../node_modules/country-flag-icons/3x2/IN.svg"); +} +.flag-io { + background-image: url("../../node_modules/country-flag-icons/3x2/IO.svg"); +} +.flag-iq { + background-image: url("../../node_modules/country-flag-icons/3x2/IQ.svg"); +} +.flag-ir { + background-image: url("../../node_modules/country-flag-icons/3x2/IR.svg"); +} +.flag-is { + background-image: url("../../node_modules/country-flag-icons/3x2/IS.svg"); +} +.flag-it { + background-image: url("../../node_modules/country-flag-icons/3x2/IT.svg"); +} +.flag-je { + background-image: url("../../node_modules/country-flag-icons/3x2/JE.svg"); +} +.flag-jm { + background-image: url("../../node_modules/country-flag-icons/3x2/JM.svg"); +} +.flag-jo { + background-image: url("../../node_modules/country-flag-icons/3x2/JO.svg"); +} +.flag-jp { + background-image: url("../../node_modules/country-flag-icons/3x2/JP.svg"); +} +.flag-ke { + background-image: url("../../node_modules/country-flag-icons/3x2/KE.svg"); +} +.flag-kg { + background-image: url("../../node_modules/country-flag-icons/3x2/KG.svg"); +} +.flag-kh { + background-image: url("../../node_modules/country-flag-icons/3x2/KH.svg"); +} +.flag-ki { + background-image: url("../../node_modules/country-flag-icons/3x2/KI.svg"); +} +.flag-km { + background-image: url("../../node_modules/country-flag-icons/3x2/KM.svg"); +} +.flag-kn { + background-image: url("../../node_modules/country-flag-icons/3x2/KN.svg"); +} +.flag-kp { + background-image: url("../../node_modules/country-flag-icons/3x2/KP.svg"); +} +.flag-kr { + background-image: url("../../node_modules/country-flag-icons/3x2/KR.svg"); +} +.flag-kw { + background-image: url("../../node_modules/country-flag-icons/3x2/KW.svg"); +} +.flag-ky { + background-image: url("../../node_modules/country-flag-icons/3x2/KY.svg"); +} +.flag-kz { + background-image: url("../../node_modules/country-flag-icons/3x2/KZ.svg"); +} +.flag-la { + background-image: url("../../node_modules/country-flag-icons/3x2/LA.svg"); +} +.flag-lb { + background-image: url("../../node_modules/country-flag-icons/3x2/LB.svg"); +} +.flag-lc { + background-image: url("../../node_modules/country-flag-icons/3x2/LC.svg"); +} +.flag-li { + background-image: url("../../node_modules/country-flag-icons/3x2/LI.svg"); +} +.flag-lk { + background-image: url("../../node_modules/country-flag-icons/3x2/LK.svg"); +} +.flag-lr { + background-image: url("../../node_modules/country-flag-icons/3x2/LR.svg"); +} +.flag-ls { + background-image: url("../../node_modules/country-flag-icons/3x2/LS.svg"); +} +.flag-lt { + background-image: url("../../node_modules/country-flag-icons/3x2/LT.svg"); +} +.flag-lu { + background-image: url("../../node_modules/country-flag-icons/3x2/LU.svg"); +} +.flag-lv { + background-image: url("../../node_modules/country-flag-icons/3x2/LV.svg"); +} +.flag-ly { + background-image: url("../../node_modules/country-flag-icons/3x2/LY.svg"); +} +.flag-ma { + background-image: url("../../node_modules/country-flag-icons/3x2/MA.svg"); +} +.flag-mc { + background-image: url("../../node_modules/country-flag-icons/3x2/MC.svg"); +} +.flag-md { + background-image: url("../../node_modules/country-flag-icons/3x2/MD.svg"); +} +.flag-me { + background-image: url("../../node_modules/country-flag-icons/3x2/ME.svg"); +} +.flag-mf { + background-image: url("../../node_modules/country-flag-icons/3x2/MF.svg"); +} +.flag-mg { + background-image: url("../../node_modules/country-flag-icons/3x2/MG.svg"); +} +.flag-mh { + background-image: url("../../node_modules/country-flag-icons/3x2/MH.svg"); +} +.flag-mk { + background-image: url("../../node_modules/country-flag-icons/3x2/MK.svg"); +} +.flag-ml { + background-image: url("../../node_modules/country-flag-icons/3x2/ML.svg"); +} +.flag-mm { + background-image: url("../../node_modules/country-flag-icons/3x2/MM.svg"); +} +.flag-mn { + background-image: url("../../node_modules/country-flag-icons/3x2/MN.svg"); +} +.flag-mo { + background-image: url("../../node_modules/country-flag-icons/3x2/MO.svg"); +} +.flag-mp { + background-image: url("../../node_modules/country-flag-icons/3x2/MP.svg"); +} +.flag-mq { + background-image: url("../../node_modules/country-flag-icons/3x2/MQ.svg"); +} +.flag-mr { + background-image: url("../../node_modules/country-flag-icons/3x2/MR.svg"); +} +.flag-ms { + background-image: url("../../node_modules/country-flag-icons/3x2/MS.svg"); +} +.flag-mt { + background-image: url("../../node_modules/country-flag-icons/3x2/MT.svg"); +} +.flag-mu { + background-image: url("../../node_modules/country-flag-icons/3x2/MU.svg"); +} +.flag-mv { + background-image: url("../../node_modules/country-flag-icons/3x2/MV.svg"); +} +.flag-mw { + background-image: url("../../node_modules/country-flag-icons/3x2/MW.svg"); +} +.flag-mx { + background-image: url("../../node_modules/country-flag-icons/3x2/MX.svg"); +} +.flag-my { + background-image: url("../../node_modules/country-flag-icons/3x2/MY.svg"); +} +.flag-mz { + background-image: url("../../node_modules/country-flag-icons/3x2/MZ.svg"); +} +.flag-na { + background-image: url("../../node_modules/country-flag-icons/3x2/NA.svg"); +} +.flag-nc { + background-image: url("../../node_modules/country-flag-icons/3x2/NC.svg"); +} +.flag-ne { + background-image: url("../../node_modules/country-flag-icons/3x2/NE.svg"); +} +.flag-nf { + background-image: url("../../node_modules/country-flag-icons/3x2/NF.svg"); +} +.flag-ng { + background-image: url("../../node_modules/country-flag-icons/3x2/NG.svg"); +} +.flag-ni { + background-image: url("../../node_modules/country-flag-icons/3x2/NI.svg"); +} +.flag-nl { + background-image: url("../../node_modules/country-flag-icons/3x2/NL.svg"); +} +.flag-no { + background-image: url("../../node_modules/country-flag-icons/3x2/NO.svg"); +} +.flag-np { + background-image: url("../../node_modules/country-flag-icons/3x2/NP.svg"); +} +.flag-nr { + background-image: url("../../node_modules/country-flag-icons/3x2/NR.svg"); +} +.flag-nu { + background-image: url("../../node_modules/country-flag-icons/3x2/NU.svg"); +} +.flag-nz { + background-image: url("../../node_modules/country-flag-icons/3x2/NZ.svg"); +} +.flag-om { + background-image: url("../../node_modules/country-flag-icons/3x2/OM.svg"); +} +.flag-pa { + background-image: url("../../node_modules/country-flag-icons/3x2/PA.svg"); +} +.flag-pe { + background-image: url("../../node_modules/country-flag-icons/3x2/PE.svg"); +} +.flag-pf { + background-image: url("../../node_modules/country-flag-icons/3x2/PF.svg"); +} +.flag-pg { + background-image: url("../../node_modules/country-flag-icons/3x2/PG.svg"); +} +.flag-ph { + background-image: url("../../node_modules/country-flag-icons/3x2/PH.svg"); +} +.flag-pk { + background-image: url("../../node_modules/country-flag-icons/3x2/PK.svg"); +} +.flag-pl { + background-image: url("../../node_modules/country-flag-icons/3x2/PL.svg"); +} +.flag-pm { + background-image: url("../../node_modules/country-flag-icons/3x2/PM.svg"); +} +.flag-pn { + background-image: url("../../node_modules/country-flag-icons/3x2/PN.svg"); +} +.flag-pr { + background-image: url("../../node_modules/country-flag-icons/3x2/PR.svg"); +} +.flag-ps { + background-image: url("../../node_modules/country-flag-icons/3x2/PS.svg"); +} +.flag-pt { + background-image: url("../../node_modules/country-flag-icons/3x2/PT.svg"); +} +.flag-pw { + background-image: url("../../node_modules/country-flag-icons/3x2/PW.svg"); +} +.flag-py { + background-image: url("../../node_modules/country-flag-icons/3x2/PY.svg"); +} +.flag-qa { + background-image: url("../../node_modules/country-flag-icons/3x2/QA.svg"); +} +.flag-re { + background-image: url("../../node_modules/country-flag-icons/3x2/RE.svg"); +} +.flag-ro { + background-image: url("../../node_modules/country-flag-icons/3x2/RO.svg"); +} +.flag-rs { + background-image: url("../../node_modules/country-flag-icons/3x2/RS.svg"); +} +.flag-ru { + background-image: url("../../node_modules/country-flag-icons/3x2/RU.svg"); +} +.flag-rw { + background-image: url("../../node_modules/country-flag-icons/3x2/RW.svg"); +} +.flag-sa { + background-image: url("../../node_modules/country-flag-icons/3x2/SA.svg"); +} +.flag-sb { + background-image: url("../../node_modules/country-flag-icons/3x2/SB.svg"); +} +.flag-sc { + background-image: url("../../node_modules/country-flag-icons/3x2/SC.svg"); +} +.flag-sd { + background-image: url("../../node_modules/country-flag-icons/3x2/SD.svg"); +} +.flag-se { + background-image: url("../../node_modules/country-flag-icons/3x2/SE.svg"); +} +.flag-sg { + background-image: url("../../node_modules/country-flag-icons/3x2/SG.svg"); +} +.flag-sh { + background-image: url("../../node_modules/country-flag-icons/3x2/SH.svg"); +} +.flag-si { + background-image: url("../../node_modules/country-flag-icons/3x2/SI.svg"); +} +.flag-sj { + background-image: url("../../node_modules/country-flag-icons/3x2/SJ.svg"); +} +.flag-sk { + background-image: url("../../node_modules/country-flag-icons/3x2/SK.svg"); +} +.flag-sl { + background-image: url("../../node_modules/country-flag-icons/3x2/SL.svg"); +} +.flag-sm { + background-image: url("../../node_modules/country-flag-icons/3x2/SM.svg"); +} +.flag-sn { + background-image: url("../../node_modules/country-flag-icons/3x2/SN.svg"); +} +.flag-so { + background-image: url("../../node_modules/country-flag-icons/3x2/SO.svg"); +} +.flag-sr { + background-image: url("../../node_modules/country-flag-icons/3x2/SR.svg"); +} +.flag-ss { + background-image: url("../../node_modules/country-flag-icons/3x2/SS.svg"); +} +.flag-st { + background-image: url("../../node_modules/country-flag-icons/3x2/ST.svg"); +} +.flag-sv { + background-image: url("../../node_modules/country-flag-icons/3x2/SV.svg"); +} +.flag-sx { + background-image: url("../../node_modules/country-flag-icons/3x2/SX.svg"); +} +.flag-sy { + background-image: url("../../node_modules/country-flag-icons/3x2/SY.svg"); +} +.flag-sz { + background-image: url("../../node_modules/country-flag-icons/3x2/SZ.svg"); +} +.flag-ta { + background-image: url("../../node_modules/country-flag-icons/3x2/TA.svg"); +} +.flag-tc { + background-image: url("../../node_modules/country-flag-icons/3x2/TC.svg"); +} +.flag-td { + background-image: url("../../node_modules/country-flag-icons/3x2/TD.svg"); +} +.flag-tf { + background-image: url("../../node_modules/country-flag-icons/3x2/TF.svg"); +} +.flag-tg { + background-image: url("../../node_modules/country-flag-icons/3x2/TG.svg"); +} +.flag-th { + background-image: url("../../node_modules/country-flag-icons/3x2/TH.svg"); +} +.flag-tj { + background-image: url("../../node_modules/country-flag-icons/3x2/TJ.svg"); +} +.flag-tk { + background-image: url("../../node_modules/country-flag-icons/3x2/TK.svg"); +} +.flag-tl { + background-image: url("../../node_modules/country-flag-icons/3x2/TL.svg"); +} +.flag-tm { + background-image: url("../../node_modules/country-flag-icons/3x2/TM.svg"); +} +.flag-tn { + background-image: url("../../node_modules/country-flag-icons/3x2/TN.svg"); +} +.flag-to { + background-image: url("../../node_modules/country-flag-icons/3x2/TO.svg"); +} +.flag-tr { + background-image: url("../../node_modules/country-flag-icons/3x2/TR.svg"); +} +.flag-tt { + background-image: url("../../node_modules/country-flag-icons/3x2/TT.svg"); +} +.flag-tv { + background-image: url("../../node_modules/country-flag-icons/3x2/TV.svg"); +} +.flag-tw { + background-image: url("../../node_modules/country-flag-icons/3x2/TW.svg"); +} +.flag-tz { + background-image: url("../../node_modules/country-flag-icons/3x2/TZ.svg"); +} +.flag-ua { + background-image: url("../../node_modules/country-flag-icons/3x2/UA.svg"); +} +.flag-ug { + background-image: url("../../node_modules/country-flag-icons/3x2/UG.svg"); +} +.flag-um { + background-image: url("../../node_modules/country-flag-icons/3x2/UM.svg"); +} +.flag-us { + background-image: url("../../node_modules/country-flag-icons/3x2/US.svg"); +} +.flag-uy { + background-image: url("../../node_modules/country-flag-icons/3x2/UY.svg"); +} +.flag-uz { + background-image: url("../../node_modules/country-flag-icons/3x2/UZ.svg"); +} +.flag-va { + background-image: url("../../node_modules/country-flag-icons/3x2/VA.svg"); +} +.flag-vc { + background-image: url("../../node_modules/country-flag-icons/3x2/VC.svg"); +} +.flag-ve { + background-image: url("../../node_modules/country-flag-icons/3x2/VE.svg"); +} +.flag-vg { + background-image: url("../../node_modules/country-flag-icons/3x2/VG.svg"); +} +.flag-vi { + background-image: url("../../node_modules/country-flag-icons/3x2/VI.svg"); +} +.flag-vn { + background-image: url("../../node_modules/country-flag-icons/3x2/VN.svg"); +} +.flag-vu { + background-image: url("../../node_modules/country-flag-icons/3x2/VU.svg"); +} +.flag-wf { + background-image: url("../../node_modules/country-flag-icons/3x2/WF.svg"); +} +.flag-ws { + background-image: url("../../node_modules/country-flag-icons/3x2/WS.svg"); +} +.flag-xa { + background-image: url("../../node_modules/country-flag-icons/3x2/XA.svg"); +} +.flag-xc { + background-image: url("../../node_modules/country-flag-icons/3x2/XC.svg"); +} +.flag-xk { + background-image: url("../../node_modules/country-flag-icons/3x2/XK.svg"); +} +.flag-xo { + background-image: url("../../node_modules/country-flag-icons/3x2/XO.svg"); +} +.flag-ye { + background-image: url("../../node_modules/country-flag-icons/3x2/YE.svg"); +} +.flag-yt { + background-image: url("../../node_modules/country-flag-icons/3x2/YT.svg"); +} +.flag-za { + background-image: url("../../node_modules/country-flag-icons/3x2/ZA.svg"); +} +.flag-zm { + background-image: url("../../node_modules/country-flag-icons/3x2/ZM.svg"); +} +.flag-zw { + background-image: url("../../node_modules/country-flag-icons/3x2/ZW.svg"); +} diff --git a/web/src/ui/motion.css b/web/src/ui/motion.css index c354889..b300862 100644 --- a/web/src/ui/motion.css +++ b/web/src/ui/motion.css @@ -49,7 +49,8 @@ /* * A popover menu opening and closing: a quick fade with a slight drop and grow from its top edge. The - * discrete transitions keep it shown while it fades out; browsers without them open and close at once. + * discrete transitions keep it shown while it fades out; browsers without them open and close at once. On a + * popover's own panel (a menu's sheet, whose popover is the dim behind it), it follows the popover. */ @utility motion-pop { transform-origin: top; @@ -62,7 +63,8 @@ scale var(--duration-fast) var(--ease-out), overlay var(--duration-fast) allow-discrete, display var(--duration-fast) allow-discrete; - &:popover-open { + &:popover-open, + :popover-open > & { opacity: 1; translate: 0; scale: 1; @@ -74,6 +76,21 @@ } } +/* A popover fading in and out in place, such as the dim behind a menu's sheet. */ +@utility motion-fade { + opacity: 0; + transition: + opacity var(--duration-fast) var(--ease-out), + overlay var(--duration-fast) allow-discrete, + display var(--duration-fast) allow-discrete; + &:popover-open { + opacity: 1; + @starting-style { + opacity: 0; + } + } +} + /* A new world record: an accent ring that pulses twice, then settles. */ @utility motion-wr-highlight { animation: sj-wr-highlight 1.6s var(--ease-in-out) both; diff --git a/web/src/ui/tabStyles.ts b/web/src/ui/tabStyles.ts index 12a5596..46a2122 100644 --- a/web/src/ui/tabStyles.ts +++ b/web/src/ui/tabStyles.ts @@ -13,8 +13,9 @@ export const tabStyles: Record< active: "border-accent text-accent", }, segmented: { - list: "inline-flex gap-1 rounded-md border border-border bg-surface p-1", - tab: "h-7 rounded-sm px-3 text-sm", + list: "inline-flex gap-1 rounded-md border border-border bg-surface p-0.5 sm:p-1", + // Smaller on phones, as tall as the menus beside it (32px) and narrow enough to share their line. + tab: "h-[26px] rounded-sm px-2 text-xs sm:h-7 sm:px-3 sm:text-sm", idle: "text-text-muted hover:bg-surface-raised hover:text-text", // Accent, like the underline variant: the chosen option has to be obvious at a glance (lead, 2026-10-20). active: "bg-accent-soft text-accent", diff --git a/web/src/ui/tokens.css b/web/src/ui/tokens.css index 01a63ce..cf6352b 100644 --- a/web/src/ui/tokens.css +++ b/web/src/ui/tokens.css @@ -74,11 +74,11 @@ --text-4xl: 3rem; --text-4xl--line-height: 3.5rem; - /* Small for badges, medium for controls and rows, large only for padded cards and dialogs. */ + /* One radius for every frame (panels, fields, buttons, menus), so edges match side by side; small for badges + and rows nested inside a frame (outer minus padding). */ --radius-*: initial; --radius-sm: 4px; --radius-md: 8px; - --radius-lg: 12px; --radius-full: 9999px; --shadow-*: initial; @@ -88,6 +88,9 @@ /* The sheet's edges: a hairline and the old site's soft blue halo. */ --shadow-sheet: 0 0 0 1px rgb(61 79 112 / 0.6), 0 0 24px 1px rgb(54 71 100 / 0.45); + /* Text laid over a picture (a map's banner), readable without darkening the picture. */ + --text-shadow-over-image: + 0 1px 2px rgb(3 8 15 / 0.9), 0 0 12px rgb(3 8 15 / 0.7); /* Motion. Durations are plain variables; the named motions in motion.css use them. */ --ease-*: initial;