Files
arena-tracker/crates/app/src/page/champ_select.rs
T
nessarandClaude Sonnet 5.5 2c9ca4552c
CI / core (pull_request) Successful in 47s
CI / core (push) Successful in 45s
Address review of the champ select page scroll
- Draw the section's grid again once the draw that moved it is over: a notify
  inside a draw dirties nothing for the next one, so its rows stayed those of
  the former place.
- Keep the first row of a grid wholly below the window built, so that Tab from
  the search enters it, and scroll the page to any card the keyboard focuses.
- Leave the scrollbar its own lane in the Anvil and « Autres champions »
  sections, so it no longer covers the sort selector, and make it a view of
  its own so that its fade does not draw the whole page.
- Store the page's Paging once; correct the performance notes on scrolling.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-22 19:18:35 +01:00

99 lines
4.2 KiB
Rust

use super::{ChampSelectTransition, Page, Tab};
use crate::worker::LiveChampSelect;
use arena_tracker_core::{account_riot_id, same_riot_id};
use gpui_kit::*;
pub(in crate::page) const UNKNOWN_ANVIL: &str =
"Champions de l'Enclume non communiqués par le client";
mod cards;
mod motion;
mod render;
impl Page {
/// 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.
pub(in crate::page) fn champ_select_account(&mut self) -> Option<String> {
let id = self.champ_select.as_ref().map(|(id, _)| id.as_str())?;
if self.champ_select_riot_id.as_deref() != Some(id) {
self.champ_select_riot_id = Some(id.into());
self.champ_select_account = self
.accounts
.iter()
.find(|a| same_riot_id(&account_riot_id(a), id))
.map(|a| a.puuid.clone());
}
self.champ_select_account.clone()
}
/// The champ select the client reports changed: entered, left, another one, or the same
/// one with new picks and bans.
pub(in crate::page) fn change_champ_select(
&mut self,
champ_select: LiveChampSelect,
window: &mut Window,
cx: &mut Context<Self>,
) {
let previous = self.champ_select.as_ref();
let next = champ_select.as_ref();
let changed_page = previous.is_some() != next.is_some();
let switch = changed_page || previous.map(|(id, _)| id) != next.map(|(id, _)| id);
self.champ_select = champ_select;
if changed_page {
if self.in_champ_select() {
// The champ select is about the Challenge, whatever tab was open.
self.tab = Tab::Challenge;
// Nothing plays during a champ select: what waited is no longer news.
self.stop_holding();
self.end_match(cx);
self.end_fade(window, cx);
// The home grid gives way to the champ select's sections.
self.home_grid
.update(cx, |grid, cx| grid.release_images(window, cx));
// Its entry plays once the window shows it (#63 reveals it without focus).
self.entry_waiting = true;
} else {
self.forget_stage();
self.reset_home_view(window, cx);
self.anvil_grid
.update(cx, |grid, cx| grid.release_images(window, cx));
// An animation asked for during the champ select plays on the home.
self.playback.stats_pending = self.playback.active();
}
}
if switch {
// The Account belongs to the signed-in Riot ID: resolve it once, not on every
// statistics preparation.
self.champ_select_riot_id = None;
self.stats_generation += 1;
self.stats = None;
self.stats_error = None;
self.forget_home();
self.stored = None;
self.reorder();
// A new champ select starts with « Autres champions » folded and searchless, at the
// top of the page.
self.fold_others(window, cx);
self.paging.scroll.set_offset(point(px(0.), px(0.)));
self.reload_in_background(window, cx);
// Nor does the banner keep the previous scope's Challenge while the new one
// loads: its Season, its ticks and its splash go with the statistics.
self.prepare_banner(cx);
}
if changed_page {
cx.emit(ChampSelectTransition {
entered: self.in_champ_select(),
});
}
// The hand as it was, to see which card an ally just took.
let before = (!switch).then(|| self.anvil_grid.read(cx).cards().clone());
// Any change (a hover or a lock-in too) changes the reasons of the cards. Only
// the client's events get here: no polling.
self.prepare_champ_select(cx);
if let Some(before) = before {
self.lower_taken(&before, window, cx);
}
self.start_entry(window, cx);
}
}