From 796fae11b7917df656d17504353e43ebad128712 Mon Sep 17 00:00:00 2001
From: TO
Date: Fri, 20 Nov 2026 21:30:50 +0100
Subject: [PATCH] Show the champion's sheet on hover and keyboard focus (#73)
The sheet covers the card with the Season's Matches, Wins, best Placement
and Attempts, and the date of the first top 1 for a Completed champion. Its
lines are prepared in Card::from_row; only the shown cards build it. The
grid keeps the hovered card and one focus handle per card id, and handles
Tab and Shift-Tab itself, scrolling the next card's row into view.
Co-Authored-By: Claude Opus 5.5
---
crates/app/src/card.rs | 183 ++++++++++++++++++++++++++++++++-
crates/app/src/card_grid.rs | 129 ++++++++++++++++++++++-
crates/app/src/main.rs | 1 +
crates/app/src/page.rs | 200 ++++++++++++++++++++++++++++++++++++
crates/app/src/text.rs | 15 +++
5 files changed, 520 insertions(+), 8 deletions(-)
diff --git a/crates/app/src/card.rs b/crates/app/src/card.rs
index 646c505..a9f882b 100644
--- a/crates/app/src/card.rs
+++ b/crates/app/src/card.rs
@@ -8,6 +8,8 @@ use gpui_kit::component::{ActiveTheme as _, Icon, IconName, StyledExt as _};
use gpui_kit::prelude::FluentBuilder as _;
use gpui_kit::*;
+use crate::text::ordinal;
+
/// Width over height.
pub const ASPECT: f32 = 0.68;
const RADIUS: f32 = 10.;
@@ -22,6 +24,18 @@ const MARK_OFF: u32 = 0xcdccd4;
const MARK_OFF_RING: u32 = 0xacaab7;
const BADGE_BG: u32 = 0x202027ee;
const BADGE_TEXT: u32 = 0xf0eff3;
+// The sheet is dark in both themes, like the shade it replaces.
+const SHEET_BG: u32 = 0x16161ef5;
+const SHEET_LABEL: u32 = 0xb4b4c3;
+
+// The sheet's lines, in order. Mastery Points will join them (one more line).
+const PLAYED: &str = "Parties";
+const WINS: &str = "Victoires";
+const BEST_PLACEMENT: &str = "Meilleur Placement";
+const ATTEMPTS: &str = "Tentatives";
+/// Only on a Completed champion.
+pub const FIRST_TOP_1: &str = "Premier top 1";
+const NONE: &str = "—";
/// Why a card is greyed out. Later tickets add the champ select's reasons (banned, taken by an
/// ally, not offered).
@@ -54,6 +68,17 @@ pub struct Card {
pub marks: Marks,
/// In display order. A card with any reason is greyed.
pub reasons: Vec,
+ /// The lines of the sheet shown on hover and focus, as label and value, prepared with the
+ /// card so showing it reads nothing.
+ pub sheet: Vec<(&'static str, SharedString)>,
+}
+
+/// What the grid knows of a card that the card does not: whether to show its sheet, and the
+/// focus handle that makes it reachable with the keyboard.
+#[derive(Clone, Copy, Default)]
+pub struct CardState<'a> {
+ pub sheet: bool,
+ pub focus: Option<&'a FocusHandle>,
}
impl Card {
@@ -77,6 +102,7 @@ impl Card {
} else {
Vec::new()
},
+ sheet: sheet_lines(row),
}
}
@@ -85,9 +111,34 @@ impl Card {
}
}
+/// The sheet's figures for the Season, all Formats; « — » where there is none (no Season, or no
+/// Match). The date is only there once the champion is Completed.
+fn sheet_lines(row: &ChampionRow) -> Vec<(&'static str, SharedString)> {
+ let challenge = row.challenge;
+ let count = |n: Option| -> SharedString {
+ n.map_or_else(|| NONE.into(), |n| n.to_string().into())
+ };
+ let mut lines = vec![
+ (PLAYED, count(challenge.map(|c| c.matches))),
+ (WINS, count(challenge.map(|c| c.wins))),
+ (
+ BEST_PLACEMENT,
+ challenge
+ .and_then(|c| c.best_placement)
+ .map_or_else(|| NONE.into(), |placement| ordinal(placement).into()),
+ ),
+ (ATTEMPTS, count(row.attempts)),
+ ];
+ if let Some(date) = challenge.and_then(|c| c.completed_on) {
+ lines.push((FIRST_TOP_1, date.to_string().into()));
+ }
+ lines
+}
+
/// One card, as wide as its parent gives it, `ASPECT` wide over tall. Hovering only changes the
-/// border colour.
-pub fn card(card: &Card, cx: &App) -> impl IntoElement {
+/// border colour; the sheet covers it when `state` says so, and a focus handle makes it a tab
+/// stop with an accent border while the keyboard is on it. The caller adds its own listeners.
+pub fn card(card: &Card, state: CardState<'_>, cx: &App) -> Stateful
{
let theme = cx.theme();
let (border, ring, background) = (theme.border, theme.ring, theme.muted);
let greyed = card.greyed();
@@ -104,6 +155,10 @@ pub fn card(card: &Card, cx: &App) -> impl IntoElement {
.border_color(border)
.bg(background)
.hover(move |style| style.border_color(ring))
+ .when_some(state.focus, |el, handle| {
+ el.track_focus(handle)
+ .focus_visible(move |style| style.border_color(ring))
+ })
.debug_selector(|| format!("card-{id}"))
.children(card.portrait.as_ref().map(|path| {
img(path.clone())
@@ -127,6 +182,47 @@ pub fn card(card: &Card, cx: &App) -> impl IntoElement {
.child(shade())
.when(greyed, |el| el.child(reasons(&card.reasons)))
.child(caption(card))
+ .when(state.sheet, |el| el.child(sheet(card)))
+}
+
+/// Over the whole card, as the mockup's `.card-info`: the name, then a line per figure. Only the
+/// shown cards build it.
+fn sheet(card: &Card) -> Div {
+ let id = card.id;
+ div()
+ .absolute()
+ .inset_0()
+ .rounded(px(INNER_RADIUS))
+ .v_flex()
+ .justify_center()
+ .p(px(12.))
+ .bg(rgba(SHEET_BG))
+ .text_size(px(12.))
+ .text_color(rgb(SHEET_LABEL))
+ .debug_selector(|| format!("sheet-{id}"))
+ .child(
+ div()
+ .mb(px(10.))
+ .text_size(px(17.))
+ .font_weight(FontWeight::SEMIBOLD)
+ .text_color(white())
+ .child(card.name.clone()),
+ )
+ .children(card.sheet.iter().map(|(label, value)| {
+ div()
+ .h_flex()
+ .justify_between()
+ .gap(px(4.))
+ .py(px(2.))
+ .debug_selector(|| format!("sheet-{id}-{label}"))
+ .child(*label)
+ .child(
+ div()
+ .font_weight(FontWeight::SEMIBOLD)
+ .text_color(white())
+ .child(value.clone()),
+ )
+ }))
}
/// Keeps the caption readable on any portrait.
@@ -231,7 +327,7 @@ mod tests {
use arena_tracker_core::{Champion, ChampionChallenge, ChampionRow, Date};
// Explicit imports: a glob of `gpui_kit` would shadow the built-in `#[test]`.
- use super::{Card, Reason};
+ use super::{Card, FIRST_TOP_1, Reason};
fn row(challenge: Option) -> ChampionRow {
ChampionRow {
@@ -316,6 +412,87 @@ mod tests {
assert_eq!(card.name.as_ref(), "Twisted Fate");
}
+ fn lines(card: &Card) -> Vec<(&'static str, String)> {
+ card.sheet
+ .iter()
+ .map(|(label, value)| (*label, value.to_string()))
+ .collect()
+ }
+
+ #[test]
+ fn the_sheet_of_a_champion_never_played_is_empty_figures_without_a_date() {
+ let mut row = row(Some(ChampionChallenge::default()));
+ row.attempts = Some(0);
+ assert_eq!(
+ lines(&Card::from_row(&row)),
+ [
+ ("Parties", "0".to_string()),
+ ("Victoires", "0".into()),
+ ("Meilleur Placement", "—".into()),
+ ("Tentatives", "0".into()),
+ ]
+ );
+ }
+
+ #[test]
+ fn the_sheet_of_a_remaining_champion_has_its_best_placement_and_no_date() {
+ let challenge = ChampionChallenge {
+ matches: 5,
+ wins: 2,
+ best_placement: Some(2),
+ completed_on: None,
+ };
+ let mut row = row(Some(challenge));
+ row.attempts = Some(5);
+ let card = Card::from_row(&row);
+ assert_eq!(
+ lines(&card),
+ [
+ ("Parties", "5".to_string()),
+ ("Victoires", "2".into()),
+ ("Meilleur Placement", "2ᵉ".into()),
+ ("Tentatives", "5".into()),
+ ]
+ );
+ assert!(card.sheet.iter().all(|(label, _)| *label != FIRST_TOP_1));
+ }
+
+ #[test]
+ fn the_sheet_of_a_completed_champion_has_the_date_of_its_first_top_1() {
+ let challenge = ChampionChallenge {
+ matches: 6,
+ wins: 3,
+ best_placement: Some(1),
+ completed_on: Some(day()),
+ };
+ let mut row = row(Some(challenge));
+ row.attempts = Some(4);
+ assert_eq!(
+ lines(&Card::from_row(&row)),
+ [
+ ("Parties", "6".to_string()),
+ ("Victoires", "3".into()),
+ ("Meilleur Placement", "1ᵉʳ".into()),
+ ("Tentatives", "4".into()),
+ ("Premier top 1", "02/03/2026".into()),
+ ]
+ );
+ }
+
+ #[test]
+ fn the_sheet_of_a_row_without_a_season_has_dashes_and_no_date() {
+ let card = Card::from_row(&row(None));
+ assert_eq!(
+ lines(&card),
+ [
+ ("Parties", "—".to_string()),
+ ("Victoires", "—".into()),
+ ("Meilleur Placement", "—".into()),
+ ("Tentatives", "—".into()),
+ ]
+ );
+ }
+
#[test]
fn a_row_without_a_challenge_has_no_marks() {
let card = Card::from_row(&row(None));
diff --git a/crates/app/src/card_grid.rs b/crates/app/src/card_grid.rs
index bd89c14..88219fd 100644
--- a/crates/app/src/card_grid.rs
+++ b/crates/app/src/card_grid.rs
@@ -1,6 +1,7 @@
//! The card grid: all the cards a list shows, in rows of the same count, only the visible rows
//! built. It is its own view because it owns the scrolling and the hover of its cards.
+use std::collections::HashMap;
use std::ops::Range;
use std::rc::Rc;
@@ -8,9 +9,23 @@ use gpui_kit::component::scroll::Scrollbar;
use gpui_kit::component::{ActiveTheme as _, StyledExt as _};
use gpui_kit::*;
-use crate::card::{ASPECT, Card, card};
+use crate::card::{ASPECT, Card, CardState, card};
use crate::page::PAGE_PADDING;
+actions!(card_grid, [NextCard, PreviousCard]);
+
+/// The grid's key context, where Tab and Shift-Tab move between its cards.
+const CONTEXT: &str = "CardGrid";
+
+/// Binds Tab and Shift-Tab in the grid's context, where they win over gpui-kit's root: the
+/// rows are virtual, so the next card may not be built yet and the root cannot reach it.
+pub fn init(cx: &mut App) {
+ cx.bind_keys([
+ KeyBinding::new("tab", NextCard, Some(CONTEXT)),
+ KeyBinding::new("shift-tab", PreviousCard, Some(CONTEXT)),
+ ]);
+}
+
/// The widest content column of the home, as in the mockup.
pub const MAX_WIDTH: f32 = 1264.;
@@ -55,12 +70,25 @@ impl Metrics {
}
}
+/// What makes one card reachable with the keyboard: its handle, and the subscriptions that draw
+/// the grid again when the focus comes or goes (a cached view is not drawn by the focus alone).
+struct CardFocus {
+ handle: FocusHandle,
+ _subscriptions: [Subscription; 2],
+}
+
pub struct CardGrid {
/// All the cards, A to Z; rebuilt only when the statistics change.
cards: Rc<[Card]>,
/// Indices into `cards`, after the filter and the search.
shown: Vec,
scroll: UniformListScrollHandle,
+ /// The card under the pointer, which shows its sheet.
+ hovered: Option,
+ /// One per card id, kept across `set_cards` and dropped with the card.
+ focus: HashMap,
+ /// The cards changed since the focus handles were last matched to them.
+ focus_stale: bool,
/// Guard the light rendering in tests.
#[cfg(test)]
pub(crate) renders: usize,
@@ -76,6 +104,9 @@ impl CardGrid {
cards: Rc::new([]),
shown: Vec::new(),
scroll: UniformListScrollHandle::new(),
+ hovered: None,
+ focus: HashMap::new(),
+ focus_stale: false,
#[cfg(test)]
renders: 0,
#[cfg(test)]
@@ -94,10 +125,72 @@ impl CardGrid {
}
if *self.cards != *cards {
self.cards = cards;
+ self.focus_stale = true;
cx.notify();
}
}
+ /// Gives every card a focus handle, reusing the ones of the ids already there. It runs when
+ /// the grid is drawn after `set_cards`, as subscribing needs the window.
+ fn sync_focus(&mut self, window: &mut Window, cx: &mut Context) {
+ self.focus_stale = false;
+ let mut previous = std::mem::take(&mut self.focus);
+ for card in self.cards.iter() {
+ let focus = previous.remove(&card.id).unwrap_or_else(|| {
+ let handle = cx.focus_handle().tab_stop(true);
+ let gained = cx.on_focus_in(&handle, window, |_, _, cx| cx.notify());
+ let lost = cx.on_focus_out(&handle, window, |_, _, _, cx| cx.notify());
+ CardFocus {
+ handle,
+ _subscriptions: [gained, lost],
+ }
+ });
+ self.focus.insert(card.id, focus);
+ }
+ }
+
+ /// Only a change of card draws the grid again.
+ fn set_hovered(&mut self, id: u32, hovered: bool, cx: &mut Context) {
+ let next = match (hovered, self.hovered) {
+ (true, _) => Some(id),
+ (false, Some(current)) if current == id => None,
+ (false, current) => current,
+ };
+ if next != self.hovered {
+ self.hovered = next;
+ cx.notify();
+ }
+ }
+
+ /// Moves the focus `step` cards on in the grid's order, scrolling its row into view since
+ /// only the visible rows are built. At either end the key goes on, to leave the grid.
+ fn move_focus(&mut self, step: isize, window: &mut Window, cx: &mut Context) {
+ let focused = |card: &Card| {
+ self.focus
+ .get(&card.id)
+ .is_some_and(|focus| focus.handle.is_focused(window))
+ };
+ let current = self
+ .shown
+ .iter()
+ .position(|&ix| self.cards.get(ix).is_some_and(focused));
+ let target = current
+ .and_then(|current| current.checked_add_signed(step))
+ .filter(|&target| target < self.shown.len());
+ let handle = target.and_then(|target| {
+ let card = self.cards.get(*self.shown.get(target)?)?;
+ Some((target, self.focus.get(&card.id)?.handle.clone()))
+ });
+ let Some((target, handle)) = handle else {
+ cx.propagate();
+ return;
+ };
+ let columns = Metrics::of(window.viewport_size().width).columns;
+ self.scroll
+ .scroll_to_item(target / columns, ScrollStrategy::Nearest);
+ window.focus(&handle, cx);
+ }
+
pub fn set_shown(&mut self, shown: Vec, cx: &mut Context) {
if self.shown != shown {
self.shown = shown;
@@ -120,7 +213,13 @@ impl CardGrid {
-self.scroll.0.borrow().base_handle.offset().y
}
- fn row(&mut self, ix: usize, metrics: Metrics, cx: &mut Context) -> AnyElement {
+ fn row(
+ &mut self,
+ ix: usize,
+ metrics: Metrics,
+ window: &Window,
+ cx: &mut Context,
+ ) -> AnyElement {
let start = ix * metrics.columns;
let row = div()
.h_flex()
@@ -138,7 +237,19 @@ impl CardGrid {
{
self.card_builds += 1;
}
- card(data, cx).into_any_element()
+ let focus = self.focus.get(&data.id).map(|focus| &focus.handle);
+ // The sheet shows on the card under the pointer and on the one the
+ // keyboard is on, as `:focus-visible` does.
+ let sheet = self.hovered == Some(data.id)
+ || focus.is_some_and(|handle| {
+ handle.is_focused(window) && window.last_input_was_keyboard()
+ });
+ let id = data.id;
+ card(data, CardState { sheet, focus }, cx)
+ .on_hover(cx.listener(move |grid, hovered: &bool, _, cx| {
+ grid.set_hovered(id, *hovered, cx)
+ }))
+ .into_any_element()
}
// The last row keeps every card the same width.
None => div().flex_1().min_w_0().into_any_element(),
@@ -154,6 +265,9 @@ impl Render for CardGrid {
{
self.renders += 1;
}
+ if self.focus_stale {
+ self.sync_focus(window, cx);
+ }
if self.shown.is_empty() {
let muted = cx.theme().muted_foreground;
return div()
@@ -169,13 +283,18 @@ impl Render for CardGrid {
div()
.relative()
.size_full()
+ .key_context(CONTEXT)
+ .on_action(cx.listener(|grid, _: &NextCard, window, cx| grid.move_focus(1, window, cx)))
+ .on_action(
+ cx.listener(|grid, _: &PreviousCard, window, cx| grid.move_focus(-1, window, cx)),
+ )
.child(
uniform_list(
"cards",
rows,
- cx.processor(move |grid, range: Range, _, cx| {
+ cx.processor(move |grid, range: Range, window, cx| {
range
- .map(|ix| grid.row(ix, metrics, cx))
+ .map(|ix| grid.row(ix, metrics, window, cx))
.collect::>()
}),
)
diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs
index 1ea570e..457f921 100644
--- a/crates/app/src/main.rs
+++ b/crates/app/src/main.rs
@@ -297,6 +297,7 @@ fn main() {
let app = gpui_kit::application().with_assets(gpui_kit::assets::Assets);
app.run(move |cx| {
gpui_kit::init(cx);
+ card_grid::init(cx);
init_theme(cx);
#[cfg(feature = "profile")]
profile::start(cx);
diff --git a/crates/app/src/page.rs b/crates/app/src/page.rs
index 91535a2..3aa78f2 100644
--- a/crates/app/src/page.rs
+++ b/crates/app/src/page.rs
@@ -1166,6 +1166,7 @@ mod tests {
tracker: Tracker,
) -> (Entity, VisualTestContext) {
cx.update(gpui_kit::init);
+ cx.update(crate::card_grid::init);
let tracker = Arc::new(tracker);
let (window, page) = cx.update(|cx| {
let (tx, rx) = unbounded();
@@ -1957,6 +1958,205 @@ mod tests {
cx.debug_bounds(id).unwrap().center()
}
+ /// `champions`, the first one Completed (first top 1 on 2 March 2026) and the second one
+ /// remaining with a 2nd place.
+ fn sheet_champions(count: u32) -> Vec {
+ let mut rows = champions(count);
+ rows[0].state = Some(ChampionState::Completed);
+ rows[0].attempts = Some(3);
+ rows[0].challenge = Some(ChampionChallenge {
+ matches: 4,
+ wins: 2,
+ best_placement: Some(1),
+ completed_on: Some(Date {
+ year: 2026,
+ month: 3,
+ day: 2,
+ }),
+ });
+ rows[1].state = Some(ChampionState::InProgress);
+ rows[1].attempts = Some(2);
+ rows[1].challenge = Some(ChampionChallenge {
+ matches: 2,
+ wins: 1,
+ best_placement: Some(2),
+ completed_on: None,
+ });
+ rows
+ }
+
+ const DATE: &str = "Premier top 1";
+
+ /// Whether the card's sheet was built in the last draw, and then whether it has the date.
+ fn sheet(cx: &mut VisualTestContext, id: u32) -> Option {
+ cx.debug_bounds(Box::leak(format!("sheet-{id}").into_boxed_str()))?;
+ Some(
+ cx.debug_bounds(Box::leak(format!("sheet-{id}-{DATE}").into_boxed_str()))
+ .is_some(),
+ )
+ }
+
+ fn sheet_ids(cx: &mut VisualTestContext, count: u32) -> Vec {
+ (1..=count).filter(|&id| sheet(cx, id).is_some()).collect()
+ }
+
+ #[gpui::test]
+ fn the_sheet_shows_on_hover_with_the_date_of_a_completed_champion_only(
+ cx: &mut TestAppContext,
+ ) {
+ let (page, cx) = open_page_in_season(cx);
+ let cx = &mut { cx };
+ show(&page, cx, statistics(1, 12, sheet_champions(12)));
+ draw(cx);
+ assert!(sheet_ids(cx, 12).is_empty(), "a sheet is built at rest");
+
+ let completed = center(cx, "card-1");
+ cx.simulate_mouse_move(completed, None, Modifiers::none());
+ draw(cx);
+ assert_eq!(sheet_ids(cx, 12), [1]);
+ assert_eq!(sheet(cx, 1), Some(true));
+
+ let remaining = center(cx, "card-2");
+ cx.simulate_mouse_move(remaining, None, Modifiers::none());
+ draw(cx);
+ assert_eq!(sheet_ids(cx, 12), [2]);
+ assert_eq!(sheet(cx, 2), Some(false));
+
+ cx.simulate_mouse_move(point(px(5.), px(5.)), None, Modifiers::none());
+ draw(cx);
+ assert!(
+ sheet_ids(cx, 12).is_empty(),
+ "the sheet stays after the pointer left"
+ );
+ }
+
+ fn press(cx: &mut VisualTestContext, keys: &str) {
+ cx.simulate_keystrokes(keys);
+ draw(cx);
+ }
+
+ #[gpui::test]
+ fn the_sheet_shows_on_keyboard_focus_and_follows_tab(cx: &mut TestAppContext) {
+ let (page, cx) = open_page_in_season(cx);
+ let cx = &mut { cx };
+ show(&page, cx, statistics(1, 40, sheet_champions(40)));
+ draw(cx);
+ let input = page.read_with(cx, |p, _| p.home_search_input.clone());
+ cx.update(|window, cx| input.update(cx, |input, cx| input.focus(window, cx)));
+ draw(cx);
+ assert!(sheet_ids(cx, 40).is_empty());
+
+ // From the search field, Tab reaches the first card, the Completed one.
+ press(cx, "tab");
+ assert_eq!(sheet_ids(cx, 40), [1]);
+ assert_eq!(sheet(cx, 1), Some(true));
+ // The next card: the previous sheet goes, the remaining champion has no date.
+ press(cx, "tab");
+ assert_eq!(sheet_ids(cx, 40), [2]);
+ assert_eq!(sheet(cx, 2), Some(false));
+ press(cx, "tab");
+ assert_eq!(sheet_ids(cx, 40), [3]);
+ // Shift-Tab goes back.
+ press(cx, "shift-tab");
+ press(cx, "shift-tab");
+ assert_eq!(sheet_ids(cx, 40), [1]);
+ assert_eq!(sheet(cx, 1), Some(true));
+ }
+
+ #[gpui::test]
+ fn tab_scrolls_the_row_of_the_next_card_into_view(cx: &mut TestAppContext) {
+ let (page, cx) = open_page_in_season(cx);
+ let cx = &mut { cx };
+ show(&page, cx, statistics(1, 170, sheet_champions(170)));
+ draw(cx);
+ let grid = page.read_with(cx, |page, _| page.home_grid.clone());
+ let input = page.read_with(cx, |p, _| p.home_search_input.clone());
+ cx.update(|window, cx| input.update(cx, |input, cx| input.focus(window, cx)));
+ draw(cx);
+ assert!(
+ cx.debug_bounds("card-25").is_none(),
+ "card 25 is already built"
+ );
+ assert_eq!(grid.read_with(cx, |grid, _| grid.scrolled()), px(0.));
+
+ // Rows of 6: the 25th card opens the 5th row, below what 860 px shows.
+ for _ in 0..25 {
+ press(cx, "tab");
+ }
+ assert_eq!(sheet_ids(cx, 170), [25]);
+ assert!(grid.read_with(cx, |grid, _| grid.scrolled()) > px(0.));
+ let bounds = cx.debug_bounds("card-25").expect("the row was not built");
+ assert!(bounds.bottom() <= px(860.), "{bounds:?}");
+
+ // Back across the row boundary, upwards.
+ for _ in 0..6 {
+ press(cx, "shift-tab");
+ }
+ assert_eq!(sheet_ids(cx, 170), [19]);
+ let bounds = cx.debug_bounds("card-19").expect("the row was not built");
+ assert!(bounds.origin.y >= px(0.), "{bounds:?}");
+ }
+
+ #[gpui::test]
+ fn tab_leaves_the_grid_after_its_last_card(cx: &mut TestAppContext) {
+ let (page, cx) = open_page_in_season(cx);
+ let cx = &mut { cx };
+ show(&page, cx, statistics(1, 3, sheet_champions(3)));
+ draw(cx);
+ let input = page.read_with(cx, |p, _| p.home_search_input.clone());
+ cx.update(|window, cx| input.update(cx, |input, cx| input.focus(window, cx)));
+ for _ in 0..3 {
+ press(cx, "tab");
+ }
+ assert_eq!(sheet_ids(cx, 3), [3]);
+ press(cx, "tab");
+ assert!(sheet_ids(cx, 3).is_empty(), "the focus stayed in the grid");
+ }
+
+ // Hovering or tabbing over the cards draws the grid and nothing upstream: the cards are not
+ // built again and no statistics are computed.
+ #[gpui::test]
+ fn showing_a_sheet_does_not_rebuild_the_cards_nor_recompute_the_statistics(
+ cx: &mut TestAppContext,
+ ) {
+ let (page, cx) = open_page_in_season(cx);
+ let cx = &mut { cx };
+ show(&page, cx, statistics(1, 170, sheet_champions(170)));
+ draw(cx);
+ let grid = page.read_with(cx, |page, _| page.home_grid.clone());
+ let generation = page.read_with(cx, |page, _| page.stats_generation);
+ let set_cards = grid.read_with(cx, |grid, _| grid.set_cards_calls);
+ let renders = grid.read_with(cx, |grid, _| grid.renders);
+
+ for id in ["card-1", "card-2", "card-1"] {
+ let card = center(cx, id);
+ cx.simulate_mouse_move(card, None, Modifiers::none());
+ draw(cx);
+ }
+ let hovered_renders = grid.read_with(cx, |grid, _| grid.renders);
+ assert!(hovered_renders > renders, "the grid was not drawn");
+
+ let input = page.read_with(cx, |p, _| p.home_search_input.clone());
+ cx.update(|window, cx| input.update(cx, |input, cx| input.focus(window, cx)));
+ for _ in 0..10 {
+ press(cx, "tab");
+ }
+ assert!(grid.read_with(cx, |grid, _| grid.renders) > hovered_renders);
+ // The key presses ended the pointer's hover: the focused card alone shows its sheet.
+ assert_eq!(sheet_ids(cx, 170), [10]);
+
+ assert_eq!(
+ grid.read_with(cx, |grid, _| grid.set_cards_calls),
+ set_cards,
+ "the cards were built again"
+ );
+ assert_eq!(
+ page.read_with(cx, |page, _| page.stats_generation),
+ generation
+ );
+ assert!(!page.read_with(cx, |page, _| page.stats_job.running()));
+ }
+
#[gpui::test]
fn the_navigation_switches_tabs_with_the_mouse(cx: &mut TestAppContext) {
let (page, cx) = open_page(cx);
diff --git a/crates/app/src/text.rs b/crates/app/src/text.rs
index 5406a56..09b1b18 100644
--- a/crates/app/src/text.rs
+++ b/crates/app/src/text.rs
@@ -16,6 +16,14 @@ pub fn stored(count: usize) -> String {
}
}
+/// A Placement as the sheet writes it: « 1ᵉʳ », « 2ᵉ », « 3ᵉ »…
+pub fn ordinal(placement: u8) -> String {
+ match placement {
+ 1 => "1ᵉʳ".into(),
+ n => format!("{n}ᵉ"),
+ }
+}
+
pub fn state_label(state: Option) -> &'static str {
match state {
Some(ChampionState::Completed) => "Validé",
@@ -69,6 +77,13 @@ mod tests {
assert_eq!(decimal(2.0 / 3.0, 1), "0,7");
}
+ #[test]
+ fn placements_are_written_as_french_ordinals() {
+ assert_eq!(ordinal(1), "1ᵉʳ");
+ assert_eq!(ordinal(2), "2ᵉ");
+ assert_eq!(ordinal(8), "8ᵉ");
+ }
+
#[test]
fn stored_matches_are_pluralised() {
assert_eq!(stored(0), "Aucune Partie enregistrée");