Show the Anvil champions as cards during an Arena champ select (#74)

The home takes the selection: the Challenge of the signed-in Account for the
current Season, then a row of the Anvil champions in the home grid's order with
the reasons Validé, Banni, Pris par un allié and Indisponible. The old text view
is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-11-20 21:32:51 +01:00
1 parent 05b8cc6d60
commit 6f2a6244cc
8 files changed
+790 -220

No files matched your search

+90 -4
View File
@@ -3,7 +3,7 @@
use std::path::PathBuf;
use arena_tracker_core::{ChampionRow, Marks};
use arena_tracker_core::{ChampionRow, Marks, Unavailability};
use gpui_kit::component::{ActiveTheme as _, Icon, IconName, StyledExt as _};
use gpui_kit::prelude::FluentBuilder as _;
use gpui_kit::*;
@@ -37,24 +37,35 @@ const ATTEMPTS: &str = "Tentatives";
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).
/// Why a card is greyed out, in the order the badges are shown.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Reason {
/// At least one top 1 in the Season.
Completed,
/// Banned in the champ select.
Banned,
/// Confirmed by an ally in the champ select.
TakenByAlly,
/// The champ select does not offer the champion.
NotOffered,
}
impl Reason {
pub fn label(self) -> &'static str {
match self {
Reason::Completed => "Validé",
Reason::Banned => "Banni",
Reason::TakenByAlly => "Pris par un allié",
Reason::NotOffered => "Indisponible",
}
}
fn icon(self) -> IconName {
match self {
Reason::Completed => IconName::Check,
Reason::Banned => IconName::Ban,
Reason::TakenByAlly => IconName::User,
Reason::NotOffered => IconName::EyeOff,
}
}
}
@@ -106,6 +117,25 @@ 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 {
banned,
taken_by_ally,
not_offered,
} = unavailability;
for (applies, reason) in [
(banned, Reason::Banned),
(taken_by_ally, Reason::TakenByAlly),
(not_offered, Reason::NotOffered),
] {
if applies {
self.reasons.push(reason);
}
}
self
}
pub fn greyed(&self) -> bool {
!self.reasons.is_empty()
}
@@ -324,7 +354,7 @@ fn mark(label: &'static str, on: bool) -> Div {
#[cfg(test)]
mod tests {
use arena_tracker_core::{Champion, ChampionChallenge, ChampionRow, Date};
use arena_tracker_core::{Champion, ChampionChallenge, ChampionRow, Date, Unavailability};
// Explicit imports: a glob of `gpui_kit` would shadow the built-in `#[test]`.
use super::{Card, FIRST_TOP_1, Reason};
@@ -499,4 +529,60 @@ mod tests {
assert_eq!(marks(&card), (false, false));
assert!(!card.greyed());
}
fn completed_row() -> ChampionRow {
row(Some(ChampionChallenge {
matches: 1,
wins: 1,
best_placement: Some(1),
completed_on: Some(day()),
}))
}
fn unavailable(banned: bool, taken_by_ally: bool, not_offered: bool) -> Unavailability {
Unavailability {
banned,
taken_by_ally,
not_offered,
}
}
#[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);
assert_eq!(
card.reasons,
[
Reason::Completed,
Reason::Banned,
Reason::TakenByAlly,
Reason::NotOffered
]
);
let labels: Vec<_> = card.reasons.iter().map(|r| r.label()).collect();
assert_eq!(
labels,
["Validé", "Banni", "Pris par un allié", "Indisponible"]
);
let card = Card::from_row(&row(None)).with_unavailability(unavailable(false, true, false));
assert_eq!(card.reasons, [Reason::TakenByAlly]);
let card =
Card::from_row(&completed_row()).with_unavailability(unavailable(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());
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());
assert_eq!(card.reasons, [Reason::Completed]);
assert!(card.greyed());
let card = Card::from_row(&row(None)).with_unavailability(unavailable(false, false, true));
assert!(card.greyed());
}
}