Keep a whole row in "Autres champions" and tidy the cards code (#75)
- "Autres champions" grid is never shorter than one card row. - A Format change keeps the home's statistics (#71); the home cards are built when "Defi" is shown again; hidden grids give back their decoded portraits; the card holds its portrait as Arc<Path>. - Unavailability becomes Unpickable (glossary), "selection" becomes "champ select" in comments (#74); the statistics error is shown by the banner only during a champ select. - Column breakpoints follow the mockup's max-width rules, the home tools row is search, filters, sort; stale comments fixed. - Tests: whole row, hidden grids, stats scopes, error shown once, and the capture's reasons end to end in the open section. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2cd8b2c545
commit
4612d89a3d
8 files changed
+535
-159
No files matched your search
+38
-26
@@ -1,9 +1,10 @@
|
||||
//! The champion card: the one representation of a champion, on the home today and in the Arena
|
||||
//! champ select later. A `Card` is built once when the statistics change; `card` only lays it out.
|
||||
//! The champion card: the one representation of a champion, on the home and in the Arena champ
|
||||
//! select. A `Card` is built once when the statistics change; `card` only lays it out.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
use arena_tracker_core::{ChampionRow, Marks, Unavailability};
|
||||
use arena_tracker_core::{ChampionRow, Marks, Unpickable};
|
||||
use gpui_kit::component::{ActiveTheme as _, Icon, IconName, StyledExt as _};
|
||||
use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::*;
|
||||
@@ -28,7 +29,7 @@ const BADGE_TEXT: u32 = 0xf0eff3;
|
||||
const SHEET_BG: u32 = 0x16161ef5;
|
||||
const SHEET_LABEL: u32 = 0xb4b4c3;
|
||||
|
||||
// The sheet's lines, in order. Mastery Points will join them (one more line).
|
||||
// The sheet's lines, in order.
|
||||
const PLAYED: &str = "Parties";
|
||||
const WINS: &str = "Victoires";
|
||||
const BEST_PLACEMENT: &str = "Meilleur Placement";
|
||||
@@ -77,7 +78,8 @@ pub struct Card {
|
||||
pub id: u32,
|
||||
pub name: SharedString,
|
||||
/// The tall portrait, else the square icon while the tall one is not downloaded yet.
|
||||
pub portrait: Option<PathBuf>,
|
||||
/// Shared, so drawing the card clones a pointer rather than a path.
|
||||
pub portrait: Option<Arc<Path>>,
|
||||
pub marks: Marks,
|
||||
/// In display order. A card with any reason is greyed.
|
||||
pub reasons: Vec<Reason>,
|
||||
@@ -108,7 +110,11 @@ impl Card {
|
||||
Card {
|
||||
id: row.champion.id,
|
||||
name: row.champion.name.clone().into(),
|
||||
portrait: row.card_portrait.clone().or_else(|| row.portrait.clone()),
|
||||
portrait: row
|
||||
.card_portrait
|
||||
.as_deref()
|
||||
.or(row.portrait.as_deref())
|
||||
.map(Arc::from),
|
||||
marks,
|
||||
reasons: if marks.completed {
|
||||
vec![Reason::Completed]
|
||||
@@ -120,12 +126,12 @@ impl Card {
|
||||
}
|
||||
|
||||
/// Adds the champ select's reasons after the Season's. The player's own pick has none.
|
||||
pub fn with_unavailability(mut self, unavailability: Unavailability) -> Card {
|
||||
let Unavailability {
|
||||
pub fn with_unpickable(mut self, unpickable: Unpickable) -> Card {
|
||||
let Unpickable {
|
||||
banned,
|
||||
taken_by_ally,
|
||||
not_offered,
|
||||
} = unavailability;
|
||||
} = unpickable;
|
||||
for (applies, reason) in [
|
||||
(banned, Reason::Banned),
|
||||
(taken_by_ally, Reason::TakenByAlly),
|
||||
@@ -218,7 +224,7 @@ pub fn card(card: &Card, state: CardState<'_>, cx: &App) -> Stateful<Div> {
|
||||
)
|
||||
})
|
||||
.child(shade())
|
||||
.when(greyed, |el| el.child(reasons(&card.reasons)))
|
||||
.when(greyed, |el| el.child(reasons(id, &card.reasons)))
|
||||
.child(caption(card))
|
||||
.when(state.sheet, |el| el.child(sheet(card)))
|
||||
}
|
||||
@@ -278,7 +284,7 @@ fn shade() -> Div {
|
||||
))
|
||||
}
|
||||
|
||||
fn reasons(reasons: &[Reason]) -> Div {
|
||||
fn reasons(id: u32, reasons: &[Reason]) -> Div {
|
||||
div()
|
||||
.absolute()
|
||||
.top(px(9.))
|
||||
@@ -300,6 +306,7 @@ fn reasons(reasons: &[Reason]) -> Div {
|
||||
.text_color(rgb(BADGE_TEXT))
|
||||
.text_size(px(10.))
|
||||
.font_weight(FontWeight::SEMIBOLD)
|
||||
.debug_selector(|| format!("reason-{id}-{}", reason.label()))
|
||||
.child(Icon::new(reason.icon()).size(px(12.)))
|
||||
.child(reason.label())
|
||||
}))
|
||||
@@ -364,7 +371,7 @@ fn mark(label: &'static str, on: bool) -> Div {
|
||||
mod tests {
|
||||
use std::path::PathBuf;
|
||||
|
||||
use arena_tracker_core::{Champion, ChampionChallenge, ChampionRow, Date, Unavailability};
|
||||
use arena_tracker_core::{Champion, ChampionChallenge, ChampionRow, Date, Unpickable};
|
||||
|
||||
// Explicit imports: a glob of `gpui_kit` would shadow the built-in `#[test]`.
|
||||
use super::{Card, FIRST_TOP_1, Reason};
|
||||
@@ -572,13 +579,19 @@ mod tests {
|
||||
card_portrait: Some(tall.clone()),
|
||||
..row(None)
|
||||
};
|
||||
assert_eq!(Card::from_row(&both).portrait, Some(tall));
|
||||
assert_eq!(
|
||||
Card::from_row(&both).portrait.as_deref(),
|
||||
Some(tall.as_path())
|
||||
);
|
||||
|
||||
let downloading = ChampionRow {
|
||||
card_portrait: None,
|
||||
..both
|
||||
};
|
||||
assert_eq!(Card::from_row(&downloading).portrait, Some(square));
|
||||
assert_eq!(
|
||||
Card::from_row(&downloading).portrait.as_deref(),
|
||||
Some(square.as_path())
|
||||
);
|
||||
|
||||
// Neither: the card keeps its plain background.
|
||||
assert_eq!(Card::from_row(&row(None)).portrait, None);
|
||||
@@ -593,8 +606,8 @@ mod tests {
|
||||
}))
|
||||
}
|
||||
|
||||
fn unavailable(banned: bool, taken_by_ally: bool, not_offered: bool) -> Unavailability {
|
||||
Unavailability {
|
||||
fn reasons_of(banned: bool, taken_by_ally: bool, not_offered: bool) -> Unpickable {
|
||||
Unpickable {
|
||||
banned,
|
||||
taken_by_ally,
|
||||
not_offered,
|
||||
@@ -603,8 +616,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn the_champ_selects_reasons_add_up_in_a_fixed_order() {
|
||||
let all = unavailable(true, true, true);
|
||||
let card = Card::from_row(&completed_row()).with_unavailability(all);
|
||||
let all = reasons_of(true, true, true);
|
||||
let card = Card::from_row(&completed_row()).with_unpickable(all);
|
||||
assert_eq!(
|
||||
card.reasons,
|
||||
[
|
||||
@@ -620,23 +633,22 @@ mod tests {
|
||||
["Validé", "Banni", "Pris par un allié", "Indisponible"]
|
||||
);
|
||||
|
||||
let card = Card::from_row(&row(None)).with_unavailability(unavailable(false, true, false));
|
||||
let card = Card::from_row(&row(None)).with_unpickable(reasons_of(false, true, false));
|
||||
assert_eq!(card.reasons, [Reason::TakenByAlly]);
|
||||
let card =
|
||||
Card::from_row(&completed_row()).with_unavailability(unavailable(true, false, false));
|
||||
let card = Card::from_row(&completed_row()).with_unpickable(reasons_of(true, false, false));
|
||||
assert_eq!(card.reasons, [Reason::Completed, Reason::Banned]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_champion_the_champ_select_does_not_hold_back_is_not_greyed_by_it() {
|
||||
let card = Card::from_row(&row(None)).with_unavailability(Unavailability::default());
|
||||
let card = Card::from_row(&row(None)).with_unpickable(Unpickable::default());
|
||||
assert!(card.reasons.is_empty());
|
||||
assert!(!card.greyed());
|
||||
// The player's own pick has no reason from the selection, but a Completed one stays.
|
||||
let card = Card::from_row(&completed_row()).with_unavailability(Unavailability::default());
|
||||
// The player's own pick has no reason from the champ select, but a Completed one stays.
|
||||
let card = Card::from_row(&completed_row()).with_unpickable(Unpickable::default());
|
||||
assert_eq!(card.reasons, [Reason::Completed]);
|
||||
assert!(card.greyed());
|
||||
let card = Card::from_row(&row(None)).with_unavailability(unavailable(false, false, true));
|
||||
let card = Card::from_row(&row(None)).with_unpickable(reasons_of(false, false, true));
|
||||
assert!(card.greyed());
|
||||
}
|
||||
}
|
||||
+38
-11
@@ -31,12 +31,13 @@ pub fn init(cx: &mut App) {
|
||||
/// The widest content column of the home, as in the mockup.
|
||||
pub const MAX_WIDTH: f32 = 1264.;
|
||||
|
||||
/// How many cards fit a row of a window `width` wide, with the mockup's breakpoints.
|
||||
/// How many cards fit a row of a window `width` wide, with the mockup's breakpoints: its
|
||||
/// `max-width` rules apply up to and including 1000, 720 and 480 px.
|
||||
fn columns(width: Pixels) -> usize {
|
||||
match width.as_f32() {
|
||||
w if w >= 1000. => 6,
|
||||
w if w >= 720. => 4,
|
||||
w if w >= 480. => 3,
|
||||
w if w > 1000. => 6,
|
||||
w if w > 720. => 4,
|
||||
w if w > 480. => 3,
|
||||
_ => 2,
|
||||
}
|
||||
}
|
||||
@@ -70,6 +71,17 @@ impl Metrics {
|
||||
card_height: (card_width / ASPECT).max(0.),
|
||||
}
|
||||
}
|
||||
|
||||
/// What one row of the list takes: a card and the gap under it.
|
||||
fn row_height(&self) -> f32 {
|
||||
self.card_height + self.gap
|
||||
}
|
||||
}
|
||||
|
||||
/// How tall a row of cards is in a window `window_width` wide: the least height that shows a
|
||||
/// whole row, for a grid that shares its column with other sections.
|
||||
pub fn row_height(window_width: Pixels) -> Pixels {
|
||||
px(Metrics::of(window_width).row_height())
|
||||
}
|
||||
|
||||
/// What makes one card reachable with the keyboard: its handle, and the subscriptions that draw
|
||||
@@ -80,7 +92,8 @@ struct CardFocus {
|
||||
}
|
||||
|
||||
pub struct CardGrid {
|
||||
/// All the cards, A to Z; rebuilt only when the statistics change.
|
||||
/// All the cards in the order the page gives (the chosen sort); replaced when the statistics
|
||||
/// or the sort change.
|
||||
cards: Rc<[Card]>,
|
||||
/// Indices into `cards`, after the filter and the search.
|
||||
shown: Vec<usize>,
|
||||
@@ -211,6 +224,19 @@ impl CardGrid {
|
||||
window.focus(&handle, cx);
|
||||
}
|
||||
|
||||
/// The grid is not shown any more: its portraits are given back, in memory and in the
|
||||
/// window's atlas, and load again when it is drawn.
|
||||
pub fn release_images(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let released = self
|
||||
.images
|
||||
.as_ref()
|
||||
.is_some_and(|images| images.update(cx, |images, cx| images.release(window, cx)));
|
||||
if released {
|
||||
// A cached view replays its last paint unless it is drawn again.
|
||||
cx.notify();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_shown(&mut self, shown: Vec<usize>, cx: &mut Context<Self>) {
|
||||
if self.shown != shown {
|
||||
self.shown = shown;
|
||||
@@ -349,6 +375,7 @@ impl Render for CardGrid {
|
||||
.into_any_element();
|
||||
}
|
||||
self.wired(div().relative().size_full(), images, cx)
|
||||
.debug_selector(|| "card-list".into())
|
||||
.child(
|
||||
uniform_list(
|
||||
"cards",
|
||||
@@ -387,12 +414,12 @@ mod tests {
|
||||
for (width, expected) in [
|
||||
(2560., 6),
|
||||
(1280., 6),
|
||||
(1000., 6),
|
||||
(999., 4),
|
||||
(720., 4),
|
||||
(719., 3),
|
||||
(480., 3),
|
||||
(479., 2),
|
||||
(1001., 6),
|
||||
(1000., 4),
|
||||
(721., 4),
|
||||
(720., 3),
|
||||
(481., 3),
|
||||
(480., 2),
|
||||
(300., 2),
|
||||
] {
|
||||
assert_eq!(columns(px(width)), expected, "{width} px");
|
||||
|
||||
@@ -52,6 +52,19 @@ impl CardImages {
|
||||
images
|
||||
}
|
||||
|
||||
/// Drops every portrait, in memory and in the window's atlas, for a grid that is no longer
|
||||
/// shown: they load again when it is drawn. A load still running is cancelled. True when
|
||||
/// something was held.
|
||||
pub fn release(&mut self, window: &mut Window, cx: &mut App) -> bool {
|
||||
let held = !self.entries.is_empty();
|
||||
for (_, entry) in self.entries.drain() {
|
||||
if let Some(Ok(image)) = entry.item.get() {
|
||||
cx.drop_image(image, Some(window));
|
||||
}
|
||||
}
|
||||
held
|
||||
}
|
||||
|
||||
/// Called first in each render of the grid. The frame on screen shows what the previous
|
||||
/// render painted, and the frame being drawn shows only what this one will paint: anything
|
||||
/// else is dropped, in memory and in the window's atlas. A load still running is cancelled.
|
||||
@@ -236,7 +249,7 @@ pub(crate) mod tests {
|
||||
Card {
|
||||
id,
|
||||
name: format!("Champion {id:03}").into(),
|
||||
portrait: Some(path),
|
||||
portrait: Some(path.into()),
|
||||
marks: Marks {
|
||||
played: false,
|
||||
won: false,
|
||||
|
||||
+388
-72
@@ -1,5 +1,6 @@
|
||||
//! The page and its two tabs: the shared state, the header row with its navigation, the banners and
|
||||
//! the champ select view. `home` and `statistics` render what is under the banners.
|
||||
//! The page and its two tabs: the shared state, the header row with its navigation and the
|
||||
//! banners. `home` (which also holds the champ select's sections) and `statistics` render what
|
||||
//! is under the banners.
|
||||
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
@@ -172,6 +173,9 @@ pub struct Page {
|
||||
/// Only for a `home_scope`.
|
||||
home_stats: Option<Statistics>,
|
||||
home_error: Option<String>,
|
||||
/// The Account and scope `home_stats` or `home_error` were computed for: the home does not
|
||||
/// depend on the Format, so a change of Format keeps them.
|
||||
home_computed: Option<(String, Scope)>,
|
||||
/// « N / total », prepared when the statistics change.
|
||||
home_count: SharedString,
|
||||
/// Completed over total, for the progress line.
|
||||
@@ -200,6 +204,8 @@ pub struct Page {
|
||||
table: Entity<ChampionTable>,
|
||||
/// The home's champions, one card each.
|
||||
home_grid: Entity<CardGrid>,
|
||||
/// The home's cards were not rebuilt for the latest statistics, as the home was not shown.
|
||||
home_cards_stale: bool,
|
||||
/// How many cards the grid shows, prepared when the filter or search change.
|
||||
home_shown_count: SharedString,
|
||||
/// The Anvil champions of the champ select, one card each in the home grid's order, with
|
||||
@@ -207,9 +213,9 @@ pub struct Page {
|
||||
anvil_grid: Entity<CardGrid>,
|
||||
/// How many Anvil champions the row shows, prepared with the cards.
|
||||
anvil_count: SharedString,
|
||||
/// « Autres champions »: folded at each new selection. While it is, it holds no card.
|
||||
/// « Autres champions »: folded at each new champ select. While it is, it holds no card.
|
||||
others_open: bool,
|
||||
/// Filters this section only; emptied with each new selection.
|
||||
/// Filters this section only; emptied with each new champ select.
|
||||
others_search: ChampionSearch,
|
||||
others_search_input: Entity<InputState>,
|
||||
/// The champions without an Anvil (all of them when the list is unknown), only built while
|
||||
@@ -400,6 +406,7 @@ impl Page {
|
||||
home_scope: None,
|
||||
home_stats: None,
|
||||
home_error: None,
|
||||
home_computed: None,
|
||||
home_count: SharedString::default(),
|
||||
home_fraction: 0.,
|
||||
home_filter: StateFilter::All,
|
||||
@@ -419,6 +426,7 @@ impl Page {
|
||||
charts,
|
||||
table,
|
||||
home_grid,
|
||||
home_cards_stale: false,
|
||||
home_shown_count: SharedString::default(),
|
||||
anvil_grid,
|
||||
anvil_count: SharedString::default(),
|
||||
@@ -519,15 +527,24 @@ impl Page {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_tab(&mut self, tab: Tab, cx: &mut Context<Self>) {
|
||||
// The selection takes the window: the Statistics tab waits for its end.
|
||||
fn set_tab(&mut self, tab: Tab, window: &mut Window, cx: &mut Context<Self>) {
|
||||
// The champ select takes the window: the Statistics tab waits for its end.
|
||||
if tab == Tab::Statistics && self.in_champ_select() {
|
||||
return;
|
||||
}
|
||||
if self.tab != tab {
|
||||
self.tab = tab;
|
||||
if tab == Tab::Statistics {
|
||||
// The home grid is not shown: its portraits are given back, and come back
|
||||
// with the grid.
|
||||
self.home_grid
|
||||
.update(cx, |grid, cx| grid.release_images(window, cx));
|
||||
}
|
||||
// The tab left was not kept up to date.
|
||||
self.refresh_table(cx);
|
||||
if self.home_cards_stale {
|
||||
self.prepare_home_cards(cx);
|
||||
}
|
||||
self.refresh_home(cx);
|
||||
cx.notify();
|
||||
}
|
||||
@@ -553,10 +570,15 @@ impl Page {
|
||||
self.champ_select = champ_select;
|
||||
if changed_page {
|
||||
if self.in_champ_select() {
|
||||
// The selection is about the Challenge, whatever tab was open.
|
||||
// The champ select is about the Challenge, whatever tab was open.
|
||||
self.tab = Tab::Challenge;
|
||||
// The home grid gives way to the champ select's sections.
|
||||
self.home_grid
|
||||
.update(cx, |grid, cx| grid.release_images(window, cx));
|
||||
} else {
|
||||
self.reset_home_view(window, cx);
|
||||
self.anvil_grid
|
||||
.update(cx, |grid, cx| grid.release_images(window, cx));
|
||||
}
|
||||
}
|
||||
if switch {
|
||||
@@ -566,11 +588,10 @@ impl Page {
|
||||
self.stats_generation += 1;
|
||||
self.stats = None;
|
||||
self.stats_error = None;
|
||||
self.home_stats = None;
|
||||
self.home_error = None;
|
||||
self.forget_home();
|
||||
self.stored = None;
|
||||
self.reorder();
|
||||
// A new selection starts with « Autres champions » folded and searchless.
|
||||
// A new champ select starts with « Autres champions » folded and searchless.
|
||||
self.fold_others(window, cx);
|
||||
self.reload_in_background(window, cx);
|
||||
}
|
||||
@@ -714,7 +735,7 @@ impl Page {
|
||||
self.stats_generation += 1;
|
||||
}
|
||||
// The home is the champ select's: its Challenge is the current Season's, which is
|
||||
// the Statistics scope for the whole selection.
|
||||
// the Statistics scope for the whole champ select.
|
||||
self.home_scope = None;
|
||||
self.current_season = self.tracker.current_season(now_ms()).map(|s| s.name);
|
||||
self.home_season = self.current_season.clone().map(Into::into);
|
||||
@@ -759,8 +780,11 @@ impl Page {
|
||||
self.home_scope = home.filter(|home| *home != self.statistics_scope());
|
||||
}
|
||||
|
||||
/// Keeps what the job computed for the home's own scope, if it had one.
|
||||
/// Keeps what was computed for the home's own scope, if it had one, and for which Account.
|
||||
fn set_home_result(&mut self, home: Option<Box<Result<Statistics, String>>>) {
|
||||
self.home_computed = home
|
||||
.as_ref()
|
||||
.and_then(|_| self.shown.clone().zip(self.home_scope.clone()));
|
||||
(self.home_stats, self.home_error) = match home.map(|result| *result) {
|
||||
Some(Ok(stats)) => (Some(stats), None),
|
||||
Some(Err(error)) => (None, Some(error)),
|
||||
@@ -768,6 +792,22 @@ impl Page {
|
||||
};
|
||||
}
|
||||
|
||||
fn forget_home(&mut self) {
|
||||
self.home_stats = None;
|
||||
self.home_error = None;
|
||||
self.home_computed = None;
|
||||
}
|
||||
|
||||
/// Whether the home's own statistics were computed for the Account and scope it has now.
|
||||
fn home_is_current(&self) -> bool {
|
||||
match (&self.shown, &self.home_scope, &self.home_computed) {
|
||||
(Some(puuid), Some(scope), Some((computed_puuid, computed_scope))) => {
|
||||
puuid == computed_puuid && scope == computed_scope
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The Account of the live champ select. Resolved when the signed-in Riot ID changes (or the
|
||||
/// Accounts do), so preparing statistics builds no Riot ID per Account every time.
|
||||
fn champ_select_account(&mut self) -> Option<String> {
|
||||
@@ -826,30 +866,35 @@ impl Page {
|
||||
}
|
||||
self.stats = None;
|
||||
self.stats_error = None;
|
||||
self.home_stats = None;
|
||||
self.home_error = None;
|
||||
self.forget_home();
|
||||
self.stored = None;
|
||||
self.show_statistics(window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
/// Recomputes the statistics for the current scope; never called while rendering.
|
||||
/// Recomputes the statistics for the current scope; never called while rendering. The home's
|
||||
/// own statistics are kept when they were computed for the same Account and scope (a change
|
||||
/// of Format leaves them as they are).
|
||||
fn recompute(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let viewed = self.prepare_statistics(true, window, cx);
|
||||
self.stats = None;
|
||||
self.stats_error = None;
|
||||
self.home_stats = None;
|
||||
self.home_error = None;
|
||||
self.stored = None;
|
||||
let keep_home = viewed.is_some() && self.home_is_current();
|
||||
if !keep_home {
|
||||
self.forget_home();
|
||||
}
|
||||
if let Some(puuid) = &viewed {
|
||||
let scope = self.statistics_scope();
|
||||
match compute_statistics(&self.tracker, puuid, &scope) {
|
||||
Ok(stats) => self.stats = Some(stats),
|
||||
Err(error) => self.stats_error = Some(error),
|
||||
}
|
||||
let home = (self.home_scope.clone())
|
||||
.map(|home| Box::new(compute_statistics(&self.tracker, puuid, &home)));
|
||||
self.set_home_result(home);
|
||||
if !keep_home {
|
||||
let home = (self.home_scope.clone())
|
||||
.map(|home| Box::new(compute_statistics(&self.tracker, puuid, &home)));
|
||||
self.set_home_result(home);
|
||||
}
|
||||
self.stored = self.tracker.match_count(puuid).ok();
|
||||
}
|
||||
self.show_statistics(window, cx);
|
||||
@@ -859,7 +904,7 @@ impl Page {
|
||||
fn show_statistics(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.reorder();
|
||||
if self.in_champ_select() {
|
||||
// Neither the charts, the table nor the home grid are shown during a selection.
|
||||
// Neither the charts, the table nor the home grid are shown during a champ select.
|
||||
self.prepare_home_labels();
|
||||
self.prepare_champ_select(cx);
|
||||
cx.notify();
|
||||
@@ -899,7 +944,7 @@ impl Page {
|
||||
}
|
||||
|
||||
/// Computes the cards' order again: for when the home statistics (the champ select's during
|
||||
/// a selection) or the sort change, and for nothing else.
|
||||
/// a champ select) or the sort change, and for nothing else.
|
||||
fn reorder(&mut self) {
|
||||
let sort = self.champion_sort.unwrap_or(ChampionSort::Mastery);
|
||||
let rows = self
|
||||
@@ -939,7 +984,13 @@ impl Page {
|
||||
}
|
||||
|
||||
/// One card per champion, in the cards' order, for when the statistics or the sort change.
|
||||
/// While the home is not shown the next switch to it does (`home_cards_stale`).
|
||||
fn prepare_home_cards(&mut self, cx: &mut Context<Self>) {
|
||||
if self.tab != Tab::Challenge {
|
||||
self.home_cards_stale = true;
|
||||
return;
|
||||
}
|
||||
self.home_cards_stale = false;
|
||||
let cards: Rc<[Card]> = self.ordered_rows().map(Card::from_row).collect();
|
||||
self.home_grid
|
||||
.update(cx, |grid, cx| grid.set_cards(cards, cx));
|
||||
@@ -973,8 +1024,7 @@ impl Page {
|
||||
self.ordered_rows()
|
||||
.filter(|row| anvil.contains(&row.champion.id))
|
||||
.map(|row| {
|
||||
Card::from_row(row)
|
||||
.with_unavailability(pick.unavailability(row.champion.id))
|
||||
Card::from_row(row).with_unpickable(pick.unpickable(row.champion.id))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -1008,9 +1058,7 @@ impl Page {
|
||||
let cards: Rc<[Card]> = match self.live_champ_select() {
|
||||
Some(pick) => self
|
||||
.other_rows()
|
||||
.map(|row| {
|
||||
Card::from_row(row).with_unavailability(pick.unavailability(row.champion.id))
|
||||
})
|
||||
.map(|row| Card::from_row(row).with_unpickable(pick.unpickable(row.champion.id)))
|
||||
.collect(),
|
||||
None => Rc::new([]),
|
||||
};
|
||||
@@ -1046,7 +1094,7 @@ impl Page {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
/// Folds « Autres champions » and empties its search, for a new selection.
|
||||
/// Folds « Autres champions » and empties its search, for a new champ select.
|
||||
fn fold_others(&mut self, window: &mut Window, cx: &mut Context<Self>) {
|
||||
if self.others_open {
|
||||
self.others_open = false;
|
||||
@@ -1124,7 +1172,7 @@ impl Page {
|
||||
.flex_shrink_0()
|
||||
.children(tabs.map(|(id, label, tab)| {
|
||||
let current = self.tab == tab;
|
||||
// The selection takes the window: « Statistiques » waits for its end.
|
||||
// The champ select takes the window: « Statistiques » waits for its end.
|
||||
let disabled = tab == Tab::Statistics && self.in_champ_select();
|
||||
BaseButton::new(id)
|
||||
.disabled(disabled)
|
||||
@@ -1146,7 +1194,7 @@ impl Page {
|
||||
.accessibility_label(label)
|
||||
.debug_selector(|| id.into())
|
||||
.child(label)
|
||||
.on_click(cx.listener(move |this, _, _, cx| this.set_tab(tab, cx)))
|
||||
.on_click(cx.listener(move |this, _, window, cx| this.set_tab(tab, window, cx)))
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -1195,7 +1243,7 @@ impl Page {
|
||||
}
|
||||
|
||||
impl Render for Page {
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let muted = cx.theme().muted_foreground;
|
||||
let busy = self.busy();
|
||||
let status_line = sync_line(busy, self.progress, self.crashed, self.stored);
|
||||
@@ -1227,7 +1275,7 @@ impl Render for Page {
|
||||
Select::new(&self.account_select)
|
||||
.id("account")
|
||||
.placeholder("Aucun Compte")
|
||||
// The selection is about the signed-in Account.
|
||||
// The champ select is about the signed-in Account.
|
||||
.disabled(self.in_champ_select())
|
||||
.w(px(260.))
|
||||
.min_w(px(150.)),
|
||||
@@ -1259,7 +1307,7 @@ impl Render for Page {
|
||||
page.child(div().v_flex().gap_1().children(self.banners()))
|
||||
})
|
||||
.children(match self.tab {
|
||||
Tab::Challenge => self.home_content(cx),
|
||||
Tab::Challenge => self.home_content(window, cx),
|
||||
Tab::Statistics => self.statistics_content(cx),
|
||||
})
|
||||
}
|
||||
@@ -1279,16 +1327,20 @@ mod tests {
|
||||
};
|
||||
use gpui_kit::base::async_util::unbounded;
|
||||
use gpui_kit::{
|
||||
AppContext as _, Bounds, Entity, KeyDownEvent, KeyUpEvent, Keystroke, Modifiers,
|
||||
ScrollDelta, ScrollEvent, TestAppContext, VisualTestContext, WindowBounds, WindowOptions,
|
||||
point, px, size,
|
||||
AppContext as _, Bounds, Entity, Focusable as _, KeyDownEvent, KeyUpEvent, Keystroke,
|
||||
Modifiers, ScrollDelta, ScrollEvent, TestAppContext, VisualTestContext, WindowBounds,
|
||||
WindowOptions, point, px, size,
|
||||
};
|
||||
|
||||
use super::{ChampionSortChosen, Page, SelectEvent, Tab};
|
||||
use crate::card::ASPECT;
|
||||
use crate::card_grid::CardGrid;
|
||||
use crate::card_grid::{CardGrid, row_height};
|
||||
use crate::champion_table::tests::row;
|
||||
|
||||
fn switch_tab(page: &Entity<Page>, cx: &mut VisualTestContext, tab: Tab) {
|
||||
cx.update(|window, cx| page.update(cx, |page, cx| page.set_tab(tab, window, cx)));
|
||||
}
|
||||
|
||||
fn open_page(cx: &mut TestAppContext) -> (Entity<Page>, VisualTestContext) {
|
||||
open_page_with_tracker(
|
||||
cx,
|
||||
@@ -1446,7 +1498,7 @@ mod tests {
|
||||
let pick = ChampSelect::new(Some(39), [39].into(), Some(vec![39]));
|
||||
window.update(|w, cx| {
|
||||
page.update(cx, |p, cx| {
|
||||
p.set_tab(Tab::Statistics, cx);
|
||||
p.set_tab(Tab::Statistics, w, cx);
|
||||
p.pinned = Some("Bob".into());
|
||||
p.season = SeasonScope::AllSeasons;
|
||||
p.filter = StateFilter::NeverPlayed;
|
||||
@@ -1457,7 +1509,7 @@ mod tests {
|
||||
});
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
page.read_with(cx, |p, cx| {
|
||||
// The selection takes the home, about the signed-in Account's current Season.
|
||||
// The champ select takes the home, about the signed-in Account's current Season.
|
||||
assert_eq!(p.tab, Tab::Challenge);
|
||||
assert_eq!(p.displayed().unwrap().puuid, "Alice");
|
||||
assert_eq!(p.home_season, p.current_season.clone().map(Into::into));
|
||||
@@ -1561,7 +1613,7 @@ mod tests {
|
||||
});
|
||||
});
|
||||
// The search field of the Statistics tab is only there on that tab.
|
||||
page.update(cx, |page, cx| page.set_tab(Tab::Statistics, cx));
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
let (input, table) = page.read_with(cx, |p, _| (p.search_input.clone(), p.table.clone()));
|
||||
let names = |cx: &mut VisualTestContext| table.read_with(cx, |table, _| table.names());
|
||||
@@ -1602,7 +1654,7 @@ mod tests {
|
||||
let (page, cx) = open_page(cx);
|
||||
let cx = &mut { cx };
|
||||
// The table hovered is the Statistics tab's: the app opens on the Challenge.
|
||||
page.update(cx, |page, cx| page.set_tab(Tab::Statistics, cx));
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
let (table, charts) =
|
||||
page.read_with(cx, |page, _| (page.table.clone(), page.charts.clone()));
|
||||
// Enough rows to fill the table, under the points hovered below.
|
||||
@@ -1859,7 +1911,7 @@ mod tests {
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
assert_eq!(charts.read_with(cx, |charts, _| charts.renders), 0);
|
||||
|
||||
page.update(cx, |page, cx| page.set_tab(Tab::Statistics, cx));
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
assert!(charts.read_with(cx, |charts, _| charts.renders) > 0);
|
||||
}
|
||||
@@ -1984,7 +2036,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_card_is_as_wide_as_the_mockups_and_a_card_without_a_portrait_renders(
|
||||
fn the_cards_keep_the_aspect_and_the_rows_their_pitch_and_a_card_without_a_portrait_renders(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
@@ -2035,6 +2087,33 @@ mod tests {
|
||||
assert!(built <= 8 * 6, "{built} cards built for 170");
|
||||
}
|
||||
|
||||
// While « Statistiques » is shown the home is not: its cards wait for the next switch to it.
|
||||
#[gpui::test]
|
||||
fn the_home_cards_are_not_built_while_statistiques_is_shown(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
let cx = &mut { cx };
|
||||
show(&page, cx, statistics(0, 5, champions(5)));
|
||||
draw(cx);
|
||||
let grid = page.read_with(cx, |page, _| page.home_grid.clone());
|
||||
let built = |cx: &mut VisualTestContext| grid.read_with(cx, |grid, _| grid.set_cards_calls);
|
||||
let calls = built(cx);
|
||||
assert!(calls > 0);
|
||||
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
show(&page, cx, statistics(0, 8, champions(8)));
|
||||
assert_eq!(built(cx), calls, "the cards were built while hidden");
|
||||
assert!(page.read_with(cx, |page, _| page.home_cards_stale));
|
||||
|
||||
switch_tab(&page, cx, Tab::Challenge);
|
||||
assert_eq!(built(cx), calls + 1);
|
||||
assert!(!page.read_with(cx, |page, _| page.home_cards_stale));
|
||||
assert_eq!(grid_names(&grid, cx).len(), 8);
|
||||
// Nothing changed meanwhile: coming back builds nothing more.
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
switch_tab(&page, cx, Tab::Challenge);
|
||||
assert_eq!(built(cx), calls + 1);
|
||||
}
|
||||
|
||||
// Hovering outside the grid draws the page again, not the cards: the grid is a cached view
|
||||
// (rule #1), like the charts row.
|
||||
#[gpui::test]
|
||||
@@ -2063,8 +2142,10 @@ mod tests {
|
||||
assert_eq!(grid.read_with(cx, |grid, _| grid.renders), renders + 1);
|
||||
}
|
||||
|
||||
// Hovering a card or scrolling the grid draws the grid, and nothing upstream: the cards are
|
||||
// not built again and no statistics are computed.
|
||||
// Hovering a card or scrolling the grid notifies the grid view, which GPUI draws again along
|
||||
// with its parent, the page (it is not a cached view). What the test proves is that this
|
||||
// costs no statistics and no cards: the statistics are not computed again and the cards are
|
||||
// not built again.
|
||||
#[gpui::test]
|
||||
fn scrolling_or_hovering_the_grid_does_not_recompute_the_statistics(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page_in_season(cx);
|
||||
@@ -2209,6 +2290,16 @@ mod tests {
|
||||
assert!(sheet_ids(cx, 170).is_empty(), "the sheet stuck to its card");
|
||||
}
|
||||
|
||||
/// The focus on the sort selector, the last stop of the home's tools before the cards.
|
||||
fn focus_sort(page: &Entity<Page>, cx: &mut VisualTestContext) {
|
||||
let select = page.read_with(cx, |p, _| p.sort_select.clone());
|
||||
cx.update(|window, cx| {
|
||||
let handle = select.read(cx).focus_handle(cx);
|
||||
window.focus(&handle, cx)
|
||||
});
|
||||
draw(cx);
|
||||
}
|
||||
|
||||
fn press(cx: &mut VisualTestContext, keys: &str) {
|
||||
cx.simulate_keystrokes(keys);
|
||||
draw(cx);
|
||||
@@ -2220,12 +2311,11 @@ mod tests {
|
||||
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)));
|
||||
focus_sort(&page, cx);
|
||||
draw(cx);
|
||||
assert!(sheet_ids(cx, 40).is_empty());
|
||||
|
||||
// From the search field, Tab reaches the first card, the Completed one.
|
||||
// From the sort selector, the last stop before the cards, 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));
|
||||
@@ -2249,8 +2339,7 @@ mod tests {
|
||||
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)));
|
||||
focus_sort(&page, cx);
|
||||
draw(cx);
|
||||
assert!(
|
||||
cx.debug_bounds("card-25").is_none(),
|
||||
@@ -2282,8 +2371,7 @@ mod tests {
|
||||
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)));
|
||||
focus_sort(&page, cx);
|
||||
for _ in 0..3 {
|
||||
press(cx, "tab");
|
||||
}
|
||||
@@ -2292,8 +2380,8 @@ mod tests {
|
||||
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.
|
||||
// Hovering or tabbing over the cards notifies the grid view (GPUI draws its parent page again
|
||||
// too): 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,
|
||||
@@ -2315,8 +2403,7 @@ mod tests {
|
||||
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)));
|
||||
focus_sort(&page, cx);
|
||||
for _ in 0..10 {
|
||||
press(cx, "tab");
|
||||
}
|
||||
@@ -2659,7 +2746,7 @@ mod tests {
|
||||
draw(&mut window);
|
||||
let first = bounds(&mut window);
|
||||
|
||||
// Never greyed by the selection: 233 and 16 are offered, the rest is not offered.
|
||||
// Never greyed by the champ select: 233 and 16 are offered, the rest is not offered.
|
||||
let baseline = [
|
||||
(233, vec![]),
|
||||
(64, vec![Reason::NotOffered]),
|
||||
@@ -2713,7 +2800,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_selection_takes_the_home_and_gives_it_back_as_it_was(cx: &mut TestAppContext) {
|
||||
async fn the_champ_select_takes_the_home_and_gives_it_back_as_it_was(cx: &mut TestAppContext) {
|
||||
use arena_tracker_core::SeasonScope;
|
||||
cx.executor().allow_parking();
|
||||
let (page, mut window) = open_page_with_tracker(cx, joueur_tracker());
|
||||
@@ -2723,7 +2810,7 @@ mod tests {
|
||||
window.update(|w, cx| {
|
||||
page.update(cx, |p, cx| {
|
||||
// Autre, on « Toutes les Saisons », with a filter and a search on the home.
|
||||
p.set_tab(Tab::Statistics, cx);
|
||||
p.set_tab(Tab::Statistics, w, cx);
|
||||
p.pinned = Some("Autre".into());
|
||||
p.season = SeasonScope::AllSeasons;
|
||||
p.home_filter = StateFilter::Completed;
|
||||
@@ -2758,13 +2845,13 @@ mod tests {
|
||||
assert!(window.debug_bounds("home-tools").is_none());
|
||||
assert!(window.debug_bounds("card-103").is_none());
|
||||
|
||||
// « Statistiques » is out of reach during the selection.
|
||||
// « Statistiques » is out of reach during the champ select.
|
||||
let statistics = center(&mut window, "tab-statistics");
|
||||
window.simulate_click(statistics, Modifiers::none());
|
||||
page.update(&mut window, |p, cx| p.set_tab(Tab::Statistics, cx));
|
||||
switch_tab(&page, &mut window, Tab::Statistics);
|
||||
assert_eq!(page.read_with(&window, |p, _| p.tab), Tab::Challenge);
|
||||
|
||||
// Bans and ally picks are the selection's.
|
||||
// Bans and ally picks are the champ select's.
|
||||
send(&page, &mut window, &with_bans_and_ally(&[16, 233], 233));
|
||||
let cards = anvil_cards(&page, &mut window);
|
||||
assert_eq!(reasons(&cards, 233), [Reason::Banned, Reason::TakenByAlly]);
|
||||
@@ -2773,7 +2860,7 @@ mod tests {
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
draw(&mut window);
|
||||
page.read_with(&window, |p, cx| {
|
||||
// As before the selection, with « Tous » and no search on the home.
|
||||
// As before the champ select, with « Tous » and no search on the home.
|
||||
assert_eq!(p.viewed().unwrap().puuid, "Autre");
|
||||
assert_eq!(p.season, SeasonScope::AllSeasons);
|
||||
assert_eq!(p.tab, Tab::Challenge);
|
||||
@@ -2792,7 +2879,7 @@ mod tests {
|
||||
assert!(window.debug_bounds("card-103").is_some());
|
||||
assert!(window.debug_bounds("anvil-row").is_none());
|
||||
|
||||
// Another selection starts clean.
|
||||
// Another champ select starts clean.
|
||||
send(&page, &mut window, &frames[0]);
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
let cards = anvil_cards(&page, &mut window);
|
||||
@@ -3000,7 +3087,7 @@ mod tests {
|
||||
activate(&mut window, "enter");
|
||||
assert!(others_open(&page, &mut window));
|
||||
|
||||
// The lock-ins of the selection reach the open section, which keeps its place.
|
||||
// The lock-ins of the champ select reach the open section, which keeps its place.
|
||||
send(&page, &mut window, &with_bans_and_ally(&[103], 25));
|
||||
draw(&mut window);
|
||||
let cards = others_cards(&page, &mut window);
|
||||
@@ -3052,7 +3139,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn a_new_selection_folds_others_and_empties_its_search(cx: &mut TestAppContext) {
|
||||
async fn a_new_champ_select_folds_others_and_empties_its_search(cx: &mut TestAppContext) {
|
||||
let frames = frames();
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames[0]).await;
|
||||
let fresh = |window: &mut VisualTestContext| {
|
||||
@@ -3064,7 +3151,7 @@ mod tests {
|
||||
})
|
||||
};
|
||||
|
||||
// The frames of the same selection keep it open, with its search.
|
||||
// The frames of the same champ select keep it open, with its search.
|
||||
click_others(&mut window);
|
||||
search_others(&page, &mut window, "ahr");
|
||||
send(&page, &mut window, &frames[1]);
|
||||
@@ -3085,7 +3172,7 @@ mod tests {
|
||||
assert!(window.debug_bounds("others-toggle").is_some());
|
||||
assert!(window.debug_bounds("card-103").is_none());
|
||||
|
||||
// The selection of another Riot ID.
|
||||
// The champ select of another Riot ID.
|
||||
click_others(&mut window);
|
||||
search_others(&page, &mut window, "cow");
|
||||
let live = Some(("Autre#EUW".to_string(), frames[0].clone()));
|
||||
@@ -3228,7 +3315,7 @@ mod tests {
|
||||
let cards = grid.shown_cards().into_iter();
|
||||
cards
|
||||
.filter(|card| card.id == 103)
|
||||
.map(|card| card.portrait)
|
||||
.map(|card| card.portrait.map(|path| path.to_path_buf()))
|
||||
.next()
|
||||
};
|
||||
assert_eq!(grid.read_with(&window, |grid, _| ahri(grid)), Some(None));
|
||||
@@ -3325,6 +3412,238 @@ mod tests {
|
||||
assert_eq!(in_atlas(&mut window), 0);
|
||||
}
|
||||
|
||||
// A grid that is not shown gives its portraits back, on the GPU too, and loads them again
|
||||
// when it is shown.
|
||||
#[gpui::test]
|
||||
async fn a_grid_that_is_not_shown_gives_its_portraits_back(cx: &mut TestAppContext) {
|
||||
cx.executor().allow_parking();
|
||||
let dir = TestDir::new("hidden-portraits");
|
||||
let keys = [
|
||||
"Ahri", "Alistar", "Briar", "LeeSin", "Morgana", "Rumble", "Soraka", "Swain", "XinZhao",
|
||||
];
|
||||
let (page, mut window) =
|
||||
open_page_with_tracker(cx, tracker_with_portraits(dir.path(), &keys));
|
||||
let load = |window: &mut VisualTestContext| {
|
||||
draw(window);
|
||||
window.run_until_parked();
|
||||
draw(window);
|
||||
};
|
||||
let held = |grid: &Entity<CardGrid>, window: &mut VisualTestContext| {
|
||||
let images = grid.read_with(window, |grid, _| grid.images().cloned());
|
||||
let images = images.expect("the grid was never drawn");
|
||||
images.read_with(window, |images, _| images.held().len())
|
||||
};
|
||||
let home = page.read_with(&window, |p, _| p.home_grid.clone());
|
||||
load(&mut window);
|
||||
assert_eq!(held(&home, &mut window), keys.len());
|
||||
let images = home.read_with(&window, |grid, _| grid.images().cloned().unwrap());
|
||||
let loaded = images.read_with(&window, |i, _| i.loaded());
|
||||
assert_eq!(loaded.len(), keys.len());
|
||||
let in_atlas = |window: &mut VisualTestContext| {
|
||||
window.update(|w, _| {
|
||||
(loaded.iter())
|
||||
.filter(|image| w.has_image_atlas_entry(image))
|
||||
.count()
|
||||
})
|
||||
};
|
||||
assert_eq!(in_atlas(&mut window), keys.len());
|
||||
|
||||
// « Statistiques » shows no card.
|
||||
switch_tab(&page, &mut window, Tab::Statistics);
|
||||
draw(&mut window);
|
||||
assert_eq!(held(&home, &mut window), 0);
|
||||
assert!(images.read_with(&window, |i, _| i.loaded()).is_empty());
|
||||
assert_eq!(in_atlas(&mut window), 0);
|
||||
|
||||
// Back on « Défi » they load again.
|
||||
switch_tab(&page, &mut window, Tab::Challenge);
|
||||
load(&mut window);
|
||||
assert_eq!(held(&home, &mut window), keys.len());
|
||||
assert_eq!(
|
||||
images.read_with(&window, |i, _| i.loaded()).len(),
|
||||
keys.len()
|
||||
);
|
||||
|
||||
// A champ select takes the home's place with its own sections.
|
||||
send(&page, &mut window, &frames()[0]);
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
load(&mut window);
|
||||
assert_eq!(held(&home, &mut window), 0);
|
||||
let anvil = page.read_with(&window, |p, _| p.anvil_grid.clone());
|
||||
assert_eq!(held(&anvil, &mut window), ANVIL.len());
|
||||
|
||||
// And gives the Anvil row up when it ends.
|
||||
leave(&page, &mut window);
|
||||
assert_eq!(held(&anvil, &mut window), 0);
|
||||
cx.condition(&page, |p, _| p.stats.is_some()).await;
|
||||
load(&mut window);
|
||||
assert_eq!(held(&home, &mut window), keys.len());
|
||||
assert_eq!(held(&anvil, &mut window), 0);
|
||||
}
|
||||
|
||||
// « Autres champions » is open in a column that also scrolls: its grid keeps at least a
|
||||
// whole row, not the sliver the Anvil row leaves it in a 860 px window.
|
||||
#[gpui::test]
|
||||
async fn the_open_others_grid_shows_a_whole_row(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
|
||||
click_others(&mut window);
|
||||
draw(&mut window);
|
||||
let list = window
|
||||
.debug_bounds("card-list")
|
||||
.expect("the open section's grid is not drawn");
|
||||
let row = row_height(px(1280.));
|
||||
assert!(
|
||||
list.size.height >= row,
|
||||
"{:?} tall for a row of {row:?}",
|
||||
list.size.height
|
||||
);
|
||||
assert!(window.debug_bounds("card-103").is_some());
|
||||
assert!(others_open(&page, &mut window));
|
||||
}
|
||||
|
||||
/// The statistics' error is the banner's alone during a champ select: the Anvil area does
|
||||
/// not repeat it, and nothing is left to browse.
|
||||
#[gpui::test]
|
||||
async fn a_statistics_error_is_said_once_during_a_champ_select(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames()[0]).await;
|
||||
let error = "Statistiques indisponibles : disque plein";
|
||||
window.update(|_, cx| {
|
||||
page.update(cx, |p, cx| {
|
||||
p.stats = None;
|
||||
p.stats_error = Some(error.into());
|
||||
p.prepare_champ_select(cx);
|
||||
cx.notify();
|
||||
})
|
||||
});
|
||||
draw(&mut window);
|
||||
page.read_with(&window, |p, _| {
|
||||
assert_eq!(p.champ_select_notice, error);
|
||||
assert_eq!(p.error().map(String::as_str), Some(error));
|
||||
});
|
||||
// The banner says it; the area says nothing and offers nothing to browse.
|
||||
assert!(window.debug_bounds("anvil-notice").is_none());
|
||||
assert!(window.debug_bounds("anvil-row").is_none());
|
||||
assert!(window.debug_bounds("others-toggle").is_none());
|
||||
assert!(window.debug_bounds("no-season").is_none());
|
||||
}
|
||||
|
||||
// The Season's statistics are computed once while the Format changes: it does not apply to
|
||||
// the home.
|
||||
#[gpui::test]
|
||||
async fn changing_the_format_recomputes_only_the_statistics_scope(cx: &mut TestAppContext) {
|
||||
use crate::worker::COMPUTED;
|
||||
use arena_tracker_core::Scope;
|
||||
let (page, mut window) = open_page_with_tracker(cx, joueur_tracker());
|
||||
let scope = |season: SeasonScope, format| Scope { season, format };
|
||||
let saison = || SeasonScope::Season("Saison".into());
|
||||
let computed = |window: &mut VisualTestContext, change: &dyn Fn(&mut Page)| {
|
||||
COMPUTED.with(|computed| computed.borrow_mut().clear());
|
||||
window.update(|w, cx| {
|
||||
page.update(cx, |p, cx| {
|
||||
change(p);
|
||||
p.recompute(w, cx)
|
||||
})
|
||||
});
|
||||
COMPUTED.with(|computed| computed.borrow().clone())
|
||||
};
|
||||
|
||||
// A Format: the statistics for it, and the home's, which were read from the former.
|
||||
let first = computed(&mut window, &|p| p.format = Some(Format::Arena3x6));
|
||||
assert_eq!(
|
||||
first,
|
||||
[
|
||||
scope(saison(), Some(Format::Arena3x6)),
|
||||
scope(saison(), None)
|
||||
]
|
||||
);
|
||||
// Another Format: the home's statistics are kept.
|
||||
let kept = page.read_with(&window, |p, _| p.home_stats.clone());
|
||||
let second = computed(&mut window, &|p| p.format = Some(Format::BraveryArena));
|
||||
assert_eq!(second, [scope(saison(), Some(Format::BraveryArena))]);
|
||||
page.read_with(&window, |p, _| {
|
||||
assert!(p.home_stats.is_some() && p.home_stats == kept);
|
||||
});
|
||||
// All the Seasons while the current one is the home's: same scope, kept.
|
||||
let third = computed(&mut window, &|p| p.season = SeasonScope::AllSeasons);
|
||||
assert_eq!(
|
||||
third,
|
||||
[scope(SeasonScope::AllSeasons, Some(Format::BraveryArena))]
|
||||
);
|
||||
// Back to « Tous les Formats » on the current Season: the statistics are the home's.
|
||||
let fourth = computed(&mut window, &|p| {
|
||||
p.season = saison();
|
||||
p.format = None;
|
||||
});
|
||||
assert_eq!(fourth, [scope(saison(), None)]);
|
||||
page.read_with(&window, |p, _| assert!(p.home_stats.is_none()));
|
||||
// A Format again: the home's statistics were the Statistics tab's, and are computed.
|
||||
let fifth = computed(&mut window, &|p| {
|
||||
p.format = Some(Format::Arena3x6);
|
||||
});
|
||||
assert_eq!(
|
||||
fifth,
|
||||
[
|
||||
scope(saison(), Some(Format::Arena3x6)),
|
||||
scope(saison(), None)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/// The reasons of the capture on the cards of « Autres champions », drawn end to end.
|
||||
#[gpui::test]
|
||||
async fn a_reason_appearing_on_a_card_of_others_is_drawn_without_moving_it(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
let frames = frames();
|
||||
let (page, mut window) = page_in_champ_select(cx, &frames[0]).await;
|
||||
click_others(&mut window);
|
||||
let name = |prefix: &str, id: u32, label: &str| -> &'static str {
|
||||
Box::leak(format!("{prefix}-{id}{label}").into_boxed_str())
|
||||
};
|
||||
let badge = |window: &mut VisualTestContext, id: u32, label: &str| {
|
||||
window
|
||||
.debug_bounds(name("reason", id, &format!("-{label}")))
|
||||
.is_some()
|
||||
};
|
||||
let places = |window: &mut VisualTestContext| {
|
||||
OTHERS_A_TO_Z.map(|id| {
|
||||
window
|
||||
.debug_bounds(name("card", id, ""))
|
||||
.expect("not drawn")
|
||||
})
|
||||
};
|
||||
let first = places(&mut window);
|
||||
for id in OTHERS_A_TO_Z {
|
||||
assert!(!badge(&mut window, id, "Banni"), "frame 0, {id}");
|
||||
}
|
||||
|
||||
// Frame 1: 12 is banned; 25 is only an ally's pre-pick, which leaves it as it is.
|
||||
send(&page, &mut window, &frames[1]);
|
||||
draw(&mut window);
|
||||
assert!(badge(&mut window, 12, "Banni"));
|
||||
assert!(!badge(&mut window, 25, "Pris par un allié"));
|
||||
assert!(!badge(&mut window, 25, "Banni"));
|
||||
assert!(!badge(&mut window, 50, "Banni"));
|
||||
assert_eq!(places(&mut window), first);
|
||||
|
||||
// Frame 2: 50 too.
|
||||
send(&page, &mut window, &frames[2]);
|
||||
draw(&mut window);
|
||||
assert!(badge(&mut window, 12, "Banni") && badge(&mut window, 50, "Banni"));
|
||||
assert!(!badge(&mut window, 25, "Pris par un allié"));
|
||||
assert_eq!(places(&mut window), first);
|
||||
|
||||
// Frame 3: the ally confirms 25.
|
||||
for frame in [&frames[3], &frames[4]] {
|
||||
send(&page, &mut window, frame);
|
||||
draw(&mut window);
|
||||
assert!(badge(&mut window, 25, "Pris par un allié"));
|
||||
assert!(badge(&mut window, 12, "Banni") && badge(&mut window, 50, "Banni"));
|
||||
assert!(!badge(&mut window, 103, "Banni"));
|
||||
assert_eq!(places(&mut window), first);
|
||||
}
|
||||
}
|
||||
|
||||
// The sort of the cards (#76).
|
||||
|
||||
/// A row with a name, an id and its Mastery Points.
|
||||
@@ -3577,9 +3896,6 @@ mod tests {
|
||||
// Entering a champ select: the Anvil row follows the sort, so does « Autres champions »,
|
||||
// and the selector stays.
|
||||
send(&page, &mut window, &frames()[0]);
|
||||
window.update(|w, cx| {
|
||||
page.update(cx, |p, cx| p.reload_in_background(w, cx));
|
||||
});
|
||||
cx.condition(&page, |p, _| {
|
||||
p.stats.as_ref().is_some_and(|s| s.rows.len() == 9)
|
||||
})
|
||||
|
||||
+27
-19
@@ -10,7 +10,7 @@ use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
use super::{Page, shown};
|
||||
use crate::card_grid::MAX_WIDTH;
|
||||
use crate::card_grid::{MAX_WIDTH, row_height};
|
||||
|
||||
/// The filters on offer, whatever the Season.
|
||||
pub(super) const FILTERS: [(&str, StateFilter); 3] = [
|
||||
@@ -27,7 +27,7 @@ impl Page {
|
||||
/// Under the banners: the Season and its counter, then the heading with the filters and
|
||||
/// search, and the cards. It holds no chart (#71): the cached charts row only belongs to the
|
||||
/// Statistics tab. Everything is one centred column, as wide as the mockup's.
|
||||
pub(super) fn home_content(&self, cx: &mut Context<Page>) -> Vec<AnyElement> {
|
||||
pub(super) fn home_content(&self, window: &Window, cx: &mut Context<Page>) -> Vec<AnyElement> {
|
||||
let mut column = div()
|
||||
.v_flex()
|
||||
.flex_1()
|
||||
@@ -40,7 +40,7 @@ impl Page {
|
||||
column = column.child(self.home_header(cx));
|
||||
}
|
||||
if self.in_champ_select() {
|
||||
// The selection takes the place of the grid, its filters and its search: the
|
||||
// The champ select takes the place of the grid, its filters and its search: the
|
||||
// column may be taller than the window, and scrolls then. « Autres champions »
|
||||
// takes what is left of the height, and scrolls by itself while open.
|
||||
if shown("anvil") {
|
||||
@@ -48,7 +48,7 @@ impl Page {
|
||||
}
|
||||
// With the statistics missing there is nothing to browse: the notice stands alone.
|
||||
if shown("others") && self.champ_select_notice.is_empty() {
|
||||
column = column.child(self.others_area(cx));
|
||||
column = column.child(self.others_area(window.viewport_size().width, cx));
|
||||
}
|
||||
return vec![
|
||||
column
|
||||
@@ -75,7 +75,7 @@ impl Page {
|
||||
}
|
||||
|
||||
/// The sort selector: a sort icon and the choice, « Maîtrise » or « A–Z ». It stays on the
|
||||
/// home and during a selection, and applies to every section of cards.
|
||||
/// home and during a champ select, and applies to every section of cards.
|
||||
fn sort_selector(&self, cx: &App) -> impl IntoElement {
|
||||
let muted = cx.theme().muted_foreground;
|
||||
div()
|
||||
@@ -153,8 +153,10 @@ impl Page {
|
||||
.child(self.sort_selector(cx)),
|
||||
)
|
||||
.children(match row {
|
||||
// The header already says there is no Season: not twice.
|
||||
// The header already says there is no Season, and a banner the statistics' error:
|
||||
// not twice.
|
||||
Some(line) if self.home_season.is_none() && line == NO_SEASON => None,
|
||||
Some(line) if self.error().is_some_and(|error| line == error.as_str()) => None,
|
||||
Some(line) => Some(
|
||||
div()
|
||||
.text_sm()
|
||||
@@ -188,8 +190,10 @@ impl Page {
|
||||
|
||||
/// « Autres champions »: a header that folds the section, and open, its search and its
|
||||
/// cards. Folded, no card is built and the grid is not even drawn. The champions are « sans
|
||||
/// enclume » only when the client gave the list: else they are all of them.
|
||||
fn others_area(&self, cx: &mut Context<Page>) -> impl IntoElement {
|
||||
/// enclume » only when the client gave the list: else they are all of them. `window_width`
|
||||
/// gives the cards' size: the grid is never shorter than a whole row, and in a small window
|
||||
/// the column scrolls instead.
|
||||
fn others_area(&self, window_width: Pixels, cx: &mut Context<Page>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let (muted, border, ring, hover, hover_foreground) = (
|
||||
theme.muted_foreground,
|
||||
@@ -244,14 +248,18 @@ impl Page {
|
||||
.child(
|
||||
// Cached, as the home's grid: hovering elsewhere does not draw its
|
||||
// cards again. Its size comes from this style.
|
||||
self.others_grid
|
||||
.clone()
|
||||
.cached(StyleRefinement::default().w_full().flex_1().min_h(px(240.))),
|
||||
self.others_grid.clone().cached(
|
||||
StyleRefinement::default()
|
||||
.w_full()
|
||||
.flex_1()
|
||||
.min_h(row_height(window_width)),
|
||||
),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/// « Mes champions » with how many cards are shown, and on the right the filters and search.
|
||||
/// « Mes champions » with how many cards are shown, and on the right the search, the filters
|
||||
/// and the sort, as the mockup's `.tools`.
|
||||
fn home_heading(&self, cx: &mut Context<Page>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let (muted, border) = (theme.muted_foreground, theme.border);
|
||||
@@ -292,7 +300,12 @@ impl Page {
|
||||
.h_flex()
|
||||
.items_center()
|
||||
.gap_3()
|
||||
.child(self.sort_selector(cx))
|
||||
.child(
|
||||
Input::new(&self.home_search_input)
|
||||
.cleanable(true)
|
||||
.w(px(260.))
|
||||
.min_w(px(150.)),
|
||||
)
|
||||
.child(
|
||||
TabBar::new("home-filter")
|
||||
.segmented()
|
||||
@@ -306,12 +319,7 @@ impl Page {
|
||||
}
|
||||
})),
|
||||
)
|
||||
.child(
|
||||
Input::new(&self.home_search_input)
|
||||
.cleanable(true)
|
||||
.w(px(260.))
|
||||
.min_w(px(150.)),
|
||||
),
|
||||
.child(self.sort_selector(cx)),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user