Fix the final champ select review findings (#13)
CI / core (pull_request) Successful in 51s
CI / core (push) Successful in 49s

This commit was merged in pull request #51.
This commit is contained in:
nessar authored and nessar committed 2026-11-19 22:17:14 +01:00
1 parent cf15eeeb8f
commit 304d958c72
12 files changed
+612 -375

No files matched your search

+10 -8
View File
@@ -83,10 +83,7 @@ impl RootView {
KeyEvent::Saved => this.page.update(cx, |page, cx| page.request_refresh(cx)),
KeyEvent::Back => {}
}
this.form.update(cx, |form, cx| form.reset(window, cx));
this.screen = Screen::Page;
this.focus.focus(window, cx);
cx.notify();
this.show_page(window, cx);
});
let champ_select = cx.subscribe_in(
&page,
@@ -94,10 +91,7 @@ impl RootView {
|this, _, _: &stats_page::ChampSelectTransition, window, cx| {
if this.screen == Screen::Settings {
// Champ select takes the window away: do not bring back half-typed edits.
this.form.update(cx, |form, cx| form.reset(window, cx));
this.screen = Screen::Page;
this.focus.focus(window, cx);
cx.notify();
this.show_page(window, cx);
}
},
);
@@ -123,6 +117,14 @@ impl RootView {
fn can_refresh(&self, cx: &App) -> bool {
self.screen != Screen::Prompt && self.form.read(cx).has_key() && !self.page.read(cx).busy()
}
/// Leaves the key form for the page, discarding half-typed edits.
fn show_page(&mut self, window: &mut Window, cx: &mut Context<Self>) {
self.form.update(cx, |form, cx| form.reset(window, cx));
self.screen = Screen::Page;
self.focus.focus(window, cx);
cx.notify();
}
}
impl Render for RootView {
+84 -61
View File
@@ -6,7 +6,7 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
use arena_tracker_core::{
Account, ChallengeSummary, ChampSelect, ChampionRow, ChampionSearch, Charts, Format,
ProgressCheck, Scope, SeasonScope, StateFilter, Statistics, Status, SyncProgress, Tracker,
UpdateProblem, same_riot_id,
UpdateProblem, account_riot_id, same_riot_id,
};
use gpui_kit::base::async_util::{Receiver, Sender};
use gpui_kit::component::StyledExt as _;
@@ -20,8 +20,8 @@ use gpui_kit::prelude::FluentBuilder as _;
use gpui_kit::*;
use crate::champion_table::ChampionTable;
use crate::text::{CLIENT_ABSENT, decimal, official_differs, official_note, riot_id, sync_line};
use crate::worker::{Msg, RefreshGate, spawn_refresh, spawn_statistics};
use crate::text::{CLIENT_ABSENT, decimal, official_differs, official_note, sync_line};
use crate::worker::{LiveChampSelect, Msg, RefreshGate, spawn_refresh, spawn_statistics};
const ALL_SEASONS: &str = "Toutes les Saisons";
const ALL_FORMATS: &str = "Tous les Formats";
@@ -32,6 +32,12 @@ const CHARTS_HEIGHT: f32 = 206.;
/// While an import runs, the page is recomputed at most this often.
const RELOAD_EVERY: Duration = Duration::from_secs(1);
fn now_ms() -> i64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.map_or(0, |d| d.as_millis() as i64)
}
/// Hides page parts for issue #27 measurements only with `--features profile`.
#[inline]
pub fn shown(part: &str) -> bool {
@@ -86,13 +92,17 @@ pub struct StatsPage {
notice: Option<String>,
/// As of the last follower round or refresh.
status: Status,
selection: crate::worker::Selection,
champ_select: LiveChampSelect,
/// The Account of `champ_select`, resolved when its Riot ID changes.
champ_select_account: Option<String>,
/// The Riot ID `champ_select_account` was resolved for.
champ_select_riot_id: Option<String>,
/// The current champion's cells, prepared when the pick or the statistics change.
current_labels: Vec<SharedString>,
/// What the panel says when the current champion has no statistics row.
current_fallback: SharedString,
/// What the panel says while the statistics are missing.
selection_notice: SharedString,
champ_select_notice: SharedString,
anvil_labels: Vec<SharedString>,
accounts: Vec<Account>,
last_active: Option<Account>,
@@ -162,10 +172,7 @@ impl StatsPage {
.map(|s| s.name.into())
.chain([ALL_SEASONS.into()])
.collect();
let now_ms = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map_or(0, |d| d.as_millis() as i64);
let current_season = tracker.current_season(now_ms).map(|s| s.name);
let current_season = tracker.current_season(now_ms()).map(|s| s.name);
let season = current_season
.clone()
.map_or(SeasonScope::AllSeasons, SeasonScope::Season);
@@ -254,10 +261,12 @@ impl StatsPage {
tracker,
tx,
notice,
selection: None,
champ_select: None,
champ_select_account: None,
champ_select_riot_id: None,
current_labels: Vec::new(),
current_fallback: SharedString::default(),
selection_notice: SharedString::default(),
champ_select_notice: SharedString::default(),
anvil_labels: Vec::new(),
accounts: Vec::new(),
last_active: None,
@@ -354,12 +363,12 @@ impl StatsPage {
}
}
Msg::Champions => self.reload_in_background(window, cx),
Msg::Selection(selection) => {
if self.selection == selection {
Msg::ChampSelect(champ_select) => {
if self.champ_select == champ_select {
return;
}
let previous = self.selection.as_ref();
let next = selection.as_ref();
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);
let pool_changed = match (previous, next) {
@@ -367,8 +376,11 @@ impl StatsPage {
(None, None) => false,
_ => true,
};
self.selection = selection;
self.champ_select = champ_select;
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;
@@ -382,9 +394,8 @@ impl StatsPage {
if pool_changed || switch {
self.refresh_table(cx);
}
// A hover or lock-in changes neither the Account nor the pool: redraw the page
// so the current-pick panel follows, even when the table is untouched.
cx.notify();
// A hover or lock-in changes neither the Account nor the pool: the page is
// redrawn by the notification at the end of this message.
}
Msg::Round { status, reload } => {
// A follower round that changes nothing shown must not rebuild the page (they keep coming).
@@ -473,11 +484,15 @@ impl StatsPage {
.iter()
.map(|a| AccountItem {
puuid: a.puuid.clone(),
title: riot_id(a).into(),
title: account_riot_id(a).into(),
})
.collect();
let changed = items != self.account_items;
self.account_items = items.clone();
if changed {
// The live champ select's Account may now be in the list: resolve it again.
self.champ_select_riot_id = None;
}
let viewed = self.viewed().map(|a| a.puuid.clone());
self.account_select.update(cx, |select, cx| {
if changed {
@@ -505,20 +520,9 @@ impl StatsPage {
if computing {
self.stats_generation += 1;
}
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default();
self.current_season = self
.tracker
.current_season(now.as_millis() as i64)
.map(|s| s.name);
let (id, _) = self.selection.as_ref()?;
return self
.accounts
.iter()
.find(|a| same_riot_id(&riot_id(a), id))
.filter(|_| self.current_season.is_some())
.map(|a| a.puuid.clone());
self.current_season = self.tracker.current_season(now_ms()).map(|s| s.name);
let puuid = self.champ_select_account()?;
return self.current_season.is_some().then_some(puuid);
}
if matches!(self.season, SeasonScope::AllSeasons)
&& !matches!(self.filter, StateFilter::All | StateFilter::NeverPlayed)
@@ -541,6 +545,21 @@ impl StatsPage {
viewed
}
/// 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> {
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()
}
fn statistics_scope(&self) -> Scope {
if self.in_champ_select()
&& let Some(season) = &self.current_season
@@ -633,11 +652,11 @@ impl StatsPage {
}
fn in_champ_select(&self) -> bool {
self.selection.is_some()
self.champ_select.is_some()
}
fn live_champ_select(&self) -> Option<&ChampSelect> {
self.selection.as_ref().map(|(_, pick)| pick)
self.champ_select.as_ref().map(|(_, pick)| pick)
}
fn update_picks(&mut self) {
@@ -667,18 +686,25 @@ impl StatsPage {
})
.unwrap_or_default();
anvil_labels.sort();
let current_fallback = match pick {
Some(s) => match s.current {
Some(id) if current_labels.is_empty() => {
let row = rows.iter().find(|r| r.champion.id == id);
format!("{} · Statistiques indisponibles", champion_label(row, id)).into()
}
Some(_) => SharedString::default(),
None => "Aucun champion sélectionné".into(),
},
None => "Sélection indisponible dans le client.".into(),
};
let selection_notice = match (&self.stats_error, self.stats.is_some()) {
// Statistics are missing rather than absent when they are still on their way.
let loading = self.stats.is_none()
&& self.stats_error.is_none()
&& self.current_season.is_some()
&& self.status.updating.is_some();
let current_fallback = pick.map_or_else(SharedString::default, |s| match s.current {
Some(id) if current_labels.is_empty() => {
let row = rows.iter().find(|r| r.champion.id == id);
let note = if loading {
"Chargement des statistiques…"
} else {
"Statistiques indisponibles"
};
format!("{} · {note}", champion_label(row, id)).into()
}
Some(_) => SharedString::default(),
None => "Aucun champion sélectionné".into(),
});
let champ_select_notice = match (&self.stats_error, self.stats.is_some()) {
(Some(error), _) => error.clone().into(),
(None, true) => SharedString::default(),
(None, false) if self.current_season.is_none() => "Aucune Saison en cours".into(),
@@ -688,13 +714,13 @@ impl StatsPage {
self.current_labels = current_labels;
self.anvil_labels = anvil_labels;
self.current_fallback = current_fallback;
self.selection_notice = selection_notice;
self.champ_select_notice = champ_select_notice;
}
fn refresh_table(&mut self, cx: &mut Context<Self>) {
let rows = self.stats.iter().flat_map(|s| &s.rows);
let rows = rows
.filter(|row| match &self.selection {
.filter(|row| match &self.champ_select {
Some((_, pick)) => pick.remaining(row),
None => self.filter.keeps(row) && self.search.matches(&row.champion),
})
@@ -709,16 +735,13 @@ impl StatsPage {
fn champ_select_view(&self, cx: &App) -> Div {
let border = cx.theme().border;
let mut page = div().v_flex().size_full().p_3().gap_3().child(
let page = div().v_flex().size_full().p_3().gap_3().child(
div()
.text_xl()
.font_weight(FontWeight::SEMIBOLD)
.child("Sélection des champions · Arena"),
);
if self.live_champ_select().is_none() {
return page.child("Sélection indisponible dans le client.");
}
page = page.child(match self.current_labels.split_first() {
page.child(match self.current_labels.split_first() {
Some((name, labels)) => div()
.h_flex()
.items_center()
@@ -733,8 +756,8 @@ impl StatsPage {
.map(|label| div().text_sm().child(label)),
),
None => div().child(self.current_fallback.clone()),
});
page.child(
})
.child(
div()
.v_flex()
.gap_2()
@@ -770,7 +793,7 @@ impl StatsPage {
.child("Champions disponibles à valider"),
)
.when(self.stats.is_none(), |page| {
page.child(self.selection_notice.clone())
page.child(self.champ_select_notice.clone())
})
.when(self.stats.is_some(), |page| {
page.child(div().flex_1().min_h_0().child(self.table.clone()))
@@ -1355,7 +1378,7 @@ mod tests {
p.filter = StateFilter::NeverPlayed;
p.reload(w, cx);
assert!(p.stats.as_ref().unwrap().rows.is_empty());
p.apply(Msg::Selection(Some(("Alice#EUW".into(), pick))), w, cx);
p.apply(Msg::ChampSelect(Some(("Alice#EUW".into(), pick))), w, cx);
})
});
cx.condition(&page, |p, _| !p.current_labels.is_empty())
@@ -1376,7 +1399,7 @@ mod tests {
let next = ChampSelect::new(None, [39].into(), vec![39]);
window.update(|w, cx| {
page.update(cx, |p, cx| {
p.apply(Msg::Selection(Some(("Alice#EUW".into(), next))), w, cx);
p.apply(Msg::ChampSelect(Some(("Alice#EUW".into(), next))), w, cx);
})
});
page.read_with(cx, |p, _| {
@@ -1386,7 +1409,7 @@ mod tests {
window.update(|w, cx| {
page.update(cx, |p, cx| {
p.apply(Msg::Selection(None), w, cx);
p.apply(Msg::ChampSelect(None), w, cx);
})
});
cx.condition(&page, |p, _| p.stats.is_some()).await;
+1 -18
View File
@@ -1,6 +1,6 @@
//! French display helpers shared by the page and the table.
use arena_tracker_core::{Account, ChampionState, SyncProgress};
use arena_tracker_core::{ChampionState, SyncProgress};
/// Fixed decimals with a decimal comma: `1,96`.
pub fn decimal(value: f64, digits: usize) -> String {
@@ -29,10 +29,6 @@ pub const CLIENT_ABSENT: &str =
"Client League of Legends non détecté : affichage des données enregistrées.";
const INTERNAL_ERROR: &str = "Mise à jour impossible : erreur interne.";
pub fn riot_id(account: &Account) -> String {
arena_tracker_core::riot_id(&account.game_name, &account.tag_line)
}
/// The discreet line under the Challenge tile.
pub fn official_note(official: u32) -> String {
format!("Progression officielle : {official}")
@@ -88,19 +84,6 @@ mod tests {
assert_eq!(state_label(None), "");
}
fn account(name: &str, tag: &str) -> Account {
Account {
puuid: "p".into(),
game_name: name.into(),
tag_line: tag.into(),
}
}
#[test]
fn riot_ids_join_name_and_tag() {
assert_eq!(riot_id(&account("Joueur", "EUW")), "Joueur#EUW");
}
#[test]
fn official_progress_texts() {
assert_eq!(official_note(52), "Progression officielle : 52");
+23 -26
View File
@@ -12,10 +12,10 @@ use arena_tracker_core::{
use gpui_kit::base::async_util::Sender;
/// The signed-in Riot ID and its pick, or none outside an Arena champ select.
pub type Selection = Option<(String, ChampSelect)>;
pub type LiveChampSelect = Option<(String, ChampSelect)>;
pub enum Msg {
Selection(Selection),
ChampSelect(LiveChampSelect),
/// A sync is fetching Matches.
Progress(SyncProgress),
/// The champion catalog and portraits were refreshed.
@@ -113,7 +113,7 @@ fn spawn_guarded(tx: Sender<Msg>, on_panic: Msg, body: impl FnOnce(&Sender<Msg>)
}
/// Keeps the active Account up to date for as long as the app runs: event-driven follower rounds
/// and a live selection subscription. Each wake reads the client once and shares that read with
/// and a live champ select subscription. Each wake reads the client once and shares that read with
/// both. `fallback_riot_id` is the configured Riot ID.
/// The champion catalog and portraits are fetched on another thread, so a first launch's
/// import never waits for them.
@@ -132,16 +132,15 @@ pub fn spawn_follower(tracker: Arc<Tracker>, fallback_riot_id: String, tx: Sende
let fallback = Some(fallback_riot_id.as_str()).filter(|id| !id.trim().is_empty());
let mut first = true;
for () in rounds {
let snapshot = history_latest.lock().unwrap().take();
// Another wake landed while this one's round ran: its read is newer and already
// queued, so this round has nothing of its own to do.
let Some(snapshot) = history_latest.lock().unwrap().take() else {
continue;
};
let mut progress = |progress| {
let _ = tx.try_send(Msg::Progress(progress));
};
let changed = match snapshot {
Some(snapshot) => {
history.follow_client_with(now_ms(), fallback, &snapshot, &mut progress)
}
None => history.follow_client(now_ms(), fallback, &mut progress),
};
let changed = history.follow_client_with(now_ms(), fallback, &snapshot, &mut progress);
if tx
.try_send(Msg::Round {
status: history.status(),
@@ -157,11 +156,11 @@ pub fn spawn_follower(tracker: Arc<Tracker>, fallback_riot_id: String, tx: Sende
spawn_guarded(tx, Msg::Crashed, move |tx| {
let mut previous = None;
let mut snapshot = tracker.client_snapshot();
let mut share = true;
let mut needs_snapshot = true;
while !tx.is_closed() {
// The follower round uses the same read as the live selection: one gameflow request
// per wake, and none for a champ select event.
if share {
// The follower round uses the same read as the live champ select: one gameflow
// request per wake, and none for a champ select event.
if needs_snapshot {
*latest.lock().unwrap() = Some(snapshot.clone());
if matches!(
wake.try_send(()),
@@ -171,24 +170,22 @@ pub fn spawn_follower(tracker: Arc<Tracker>, fallback_riot_id: String, tx: Sende
}
}
match tracker.champ_select_with(&snapshot) {
Ok(selection) if selection != previous => {
if tx.try_send(Msg::Selection(selection.clone())).is_err() {
Ok(champ_select) if champ_select != previous => {
if tx.try_send(Msg::ChampSelect(champ_select.clone())).is_err() {
break;
}
previous = selection;
previous = champ_select;
}
Ok(_) => {}
// A failed read is not the draft ending: keep what the page shows.
// A failed read is not the champ select ending: keep what the page shows.
Err(_) => {}
}
// A champ select event costs no request while the draft is already known; any other
// event, or a snapshot that predates the draft, needs a fresh read.
share = tracker.wait_for_client() == ClientEvent::Other
|| !snapshot
.gameflow
.as_ref()
.is_ok_and(|flow| flow.is_arena_champ_select());
if share {
// A champ select event costs no request once a read has answered: only a gameflow
// event, or a read that failed, needs a fresh one. The gameflow event that starts
// the champ select is that event.
needs_snapshot =
tracker.wait_for_client() == ClientEvent::Other || snapshot.gameflow.is_err();
if needs_snapshot {
snapshot = tracker.client_snapshot();
}
}