Filter « Parties » by Season, Format, Placement and champion (#126)
Season and Format are the Statistics page's own selectors; Placement offers « Tous · Top 1 · Victoires » and the search is the home's, aliases included. Filtering works on the rows already loaded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
61bd6114ff
commit
4c68fd2814
11 files changed
+833
-68
No files matched your search
@@ -4,25 +4,27 @@
|
||||
//! nothing runs while the screen is hidden but marking the list stale (rule #1).
|
||||
|
||||
mod details;
|
||||
mod filters;
|
||||
mod list;
|
||||
mod recap;
|
||||
mod screen;
|
||||
mod shown;
|
||||
|
||||
use filters::Filters;
|
||||
use list::MatchChosen;
|
||||
pub(in crate::page) use list::MatchList;
|
||||
#[cfg(test)]
|
||||
pub(in crate::page) use list::MatchRow as Row;
|
||||
pub use list::init;
|
||||
use list::{MatchChosen, MatchRow};
|
||||
use shown::{Champions, ShownRecap};
|
||||
#[cfg(test)]
|
||||
pub(in crate::page) use shown::{ShownPlayer, Slot, UNAVAILABLE};
|
||||
|
||||
use super::{Page, Tab};
|
||||
use crate::card_images::CardImages;
|
||||
use crate::text::ordinal;
|
||||
use crate::worker::{MatchEntry, RefreshGate, spawn_match_list, spawn_recap};
|
||||
use arena_tracker_core::MatchRecap;
|
||||
use arena_tracker_core::{MatchRecap, Season};
|
||||
use gpui_kit::component::input::InputEvent;
|
||||
use gpui_kit::*;
|
||||
|
||||
/// The recap beside the list.
|
||||
@@ -51,6 +53,10 @@ pub(in crate::page) struct Matches {
|
||||
puuid: Option<String>,
|
||||
/// Its Matches, newest first; `None` until the first list of that Account arrives.
|
||||
entries: Option<Vec<MatchEntry>>,
|
||||
/// The positions in `entries` of the Matches the filters keep, as the list shows them.
|
||||
visible: Vec<usize>,
|
||||
/// The filters of the screen that « Statistiques » does not share.
|
||||
filters: Filters,
|
||||
/// Why the last list failed: the Matches already known stay.
|
||||
error: Option<SharedString>,
|
||||
/// The stored Matches may have changed since the list was read.
|
||||
@@ -67,18 +73,32 @@ pub(in crate::page) struct Matches {
|
||||
/// In a narrow window, the list is open over the recap.
|
||||
pub(in crate::page) list_open: bool,
|
||||
_chosen: Subscription,
|
||||
_searched: Subscription,
|
||||
}
|
||||
|
||||
impl Matches {
|
||||
pub(in crate::page) fn new(cx: &mut Context<Page>) -> Matches {
|
||||
/// `seasons`: the Season table, which says what Season each Match is of.
|
||||
pub(in crate::page) fn new(
|
||||
seasons: &[Season],
|
||||
window: &mut Window,
|
||||
cx: &mut Context<Page>,
|
||||
) -> Matches {
|
||||
let list = cx.new(MatchList::new);
|
||||
let chosen = cx.subscribe(&list, |page, _, event: &MatchChosen, cx| {
|
||||
page.choose_match(event.match_id.clone(), event.close, cx)
|
||||
});
|
||||
let filters = Filters::new(seasons, window, cx);
|
||||
let searched = cx.subscribe(&filters.input, |page, _, event: &InputEvent, cx| {
|
||||
if matches!(event, InputEvent::Change) {
|
||||
page.matches_searched(cx);
|
||||
}
|
||||
});
|
||||
Matches {
|
||||
list,
|
||||
puuid: None,
|
||||
entries: None,
|
||||
visible: Vec::new(),
|
||||
filters,
|
||||
error: None,
|
||||
stale: true,
|
||||
job: RefreshGate::default(),
|
||||
@@ -90,6 +110,7 @@ impl Matches {
|
||||
recap_images: CardImages::new(cx),
|
||||
list_open: false,
|
||||
_chosen: chosen,
|
||||
_searched: searched,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +119,11 @@ impl Matches {
|
||||
self.entries.as_deref()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(in crate::page) fn search_input(&self) -> &Entity<gpui_kit::component::input::InputState> {
|
||||
&self.filters.input
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(in crate::page) fn recap_images(&self) -> &Entity<CardImages> {
|
||||
&self.recap_images
|
||||
@@ -139,6 +165,7 @@ impl Page {
|
||||
if puuid != matches.puuid {
|
||||
matches.puuid = puuid;
|
||||
matches.entries = None;
|
||||
matches.visible.clear();
|
||||
matches.error = None;
|
||||
matches.selected = None;
|
||||
matches.recap = Recap::None;
|
||||
@@ -179,7 +206,7 @@ impl Page {
|
||||
}
|
||||
|
||||
/// The screen arrives: the list is read again if the stored Matches changed, and the most
|
||||
/// recent Match is chosen, the previous choice forgotten.
|
||||
/// recent Match the filters keep is chosen, the previous choice forgotten.
|
||||
pub(in crate::page) fn open_matches(&mut self, cx: &mut Context<Self>) {
|
||||
let matches = &mut self.matches;
|
||||
matches.selected = None;
|
||||
@@ -190,9 +217,8 @@ impl Page {
|
||||
if matches.stale || matches.entries.is_none() {
|
||||
// The most recent is chosen when the list arrives.
|
||||
self.request_matches();
|
||||
} else {
|
||||
self.choose_newest();
|
||||
}
|
||||
// Else the most recent is chosen with the list written.
|
||||
self.dress_matches(cx);
|
||||
}
|
||||
|
||||
@@ -245,25 +271,18 @@ impl Page {
|
||||
matches.error = None;
|
||||
let previous = matches.entries.replace(entries).unwrap_or_default();
|
||||
let entries = matches.entries.as_deref().unwrap_or_default();
|
||||
// The Match chosen stays chosen while it is listed, as a sync lists them again.
|
||||
let kept = (matches.selected.as_ref())
|
||||
// The Match chosen stays chosen while it is listed and kept by the filters, as a sync
|
||||
// lists them again; the filters choose another when it is not.
|
||||
let corrected = (matches.selected.as_ref())
|
||||
.and_then(|id| entries.iter().find(|entry| entry.match_id == *id))
|
||||
// Published or corrected meanwhile: decoded again.
|
||||
.map(|entry| previous.contains(entry));
|
||||
match kept {
|
||||
Some(true) => {}
|
||||
Some(false) => self.request_recap(),
|
||||
None => self.choose_newest(),
|
||||
.is_some_and(|entry| !previous.contains(entry));
|
||||
if corrected {
|
||||
self.request_recap();
|
||||
}
|
||||
self.dress_matches(cx);
|
||||
}
|
||||
|
||||
fn choose_newest(&mut self) {
|
||||
let newest = (self.matches.entries.iter().flatten().next()).map(|e| e.match_id.clone());
|
||||
self.matches.selected = newest;
|
||||
self.request_recap();
|
||||
}
|
||||
|
||||
/// The list chose a Match: its recap is decoded.
|
||||
fn choose_match(&mut self, match_id: String, close: bool, cx: &mut Context<Self>) {
|
||||
if close {
|
||||
@@ -367,27 +386,15 @@ impl Page {
|
||||
.map_or((0, ""), |e| (e.champion_id, e.champion_name.as_str()))
|
||||
}
|
||||
|
||||
/// Writes the rows of the list and the recap with the champions' names and portraits, which
|
||||
/// the statistics may bring after the Matches.
|
||||
/// Keeps the Matches the filters leave, writes the rows of the list and the recap with the
|
||||
/// champions' names and portraits, which the statistics may bring after the Matches, and
|
||||
/// chooses the first Match kept when the one chosen is not.
|
||||
pub(in crate::page) fn dress_matches(&mut self, cx: &mut Context<Self>) {
|
||||
if self.shown_tab != Tab::Matches && self.tab != Tab::Matches {
|
||||
return;
|
||||
}
|
||||
let champions = self.champions();
|
||||
let rows: Vec<MatchRow> = (self.matches.entries.iter().flatten())
|
||||
.map(|entry| MatchRow {
|
||||
match_id: entry.match_id.clone(),
|
||||
champion: champions.name(entry.champion_id, &entry.champion_name),
|
||||
portrait: champions.portrait(entry.champion_id),
|
||||
when: entry.when.clone().into(),
|
||||
placement: ordinal(entry.placement).into(),
|
||||
provisional: entry.provisional,
|
||||
})
|
||||
.collect();
|
||||
let selected = self.matches.selected.clone();
|
||||
self.matches
|
||||
.list
|
||||
.update(cx, |list, cx| list.set_rows(rows, selected.as_deref(), cx));
|
||||
self.refilter(&champions, cx);
|
||||
let champion = self.chosen_champion();
|
||||
let champion = (champion.0, champion.1.to_string());
|
||||
if let Recap::Ready { recap, shown, .. } = &mut self.matches.recap {
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
//! The filters of « Parties »: Season and Format (the selectors and the choice of « Statistiques »,
|
||||
//! one state for both pages), Placement and champion search (its own). They narrow the Matches
|
||||
//! already loaded: no query is made, and only the rows kept are written to the list.
|
||||
|
||||
use std::ops::Range;
|
||||
|
||||
use arena_tracker_core::{ChampionSearch, Season, SeasonScope};
|
||||
use gpui_kit::base::Button as BaseButton;
|
||||
use gpui_kit::component::ActiveTheme as _;
|
||||
use gpui_kit::component::StyledExt as _;
|
||||
use gpui_kit::component::input::{Input, InputState};
|
||||
use gpui_kit::component::select::Select;
|
||||
use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
use super::list::MatchRow;
|
||||
use super::shown::Champions;
|
||||
use crate::page::{Page, Tab};
|
||||
use crate::text::ordinal;
|
||||
use crate::worker::MatchEntry;
|
||||
|
||||
/// What the list says when the filters leave no Match.
|
||||
pub(super) const NO_RESULT: &str = "Aucune Partie ne correspond aux filtres";
|
||||
|
||||
/// « Tous · Top 1 · Victoires ».
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub(in crate::page) enum PlacementFilter {
|
||||
All,
|
||||
/// A Placement of 1.
|
||||
Top1,
|
||||
/// The Matches the game itself counts as won.
|
||||
Wins,
|
||||
}
|
||||
|
||||
/// Each choice with its label and the id the tests click.
|
||||
const PLACEMENTS: [(&str, &str, PlacementFilter); 3] = [
|
||||
("matches-placement-all", "Tous", PlacementFilter::All),
|
||||
("matches-placement-top1", "Top 1", PlacementFilter::Top1),
|
||||
("matches-placement-wins", "Victoires", PlacementFilter::Wins),
|
||||
];
|
||||
|
||||
impl PlacementFilter {
|
||||
fn keeps(self, entry: &MatchEntry) -> bool {
|
||||
match self {
|
||||
PlacementFilter::All => true,
|
||||
PlacementFilter::Top1 => entry.placement == 1,
|
||||
PlacementFilter::Wins => entry.win,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The filters of the list that « Statistiques » does not have.
|
||||
pub(super) struct Filters {
|
||||
pub(super) placement: PlacementFilter,
|
||||
pub(super) search: ChampionSearch,
|
||||
/// The search has a query: the champions are only looked up then.
|
||||
searching: bool,
|
||||
pub(super) input: Entity<InputState>,
|
||||
/// Each Season's period in epoch ms, as the statistics cut them: from its start to the next
|
||||
/// one's, the last open-ended.
|
||||
periods: Vec<(String, Range<i64>)>,
|
||||
}
|
||||
|
||||
impl Filters {
|
||||
/// `seasons`: the Season table, oldest first.
|
||||
pub(super) fn new(seasons: &[Season], window: &mut Window, cx: &mut App) -> Filters {
|
||||
Filters {
|
||||
placement: PlacementFilter::All,
|
||||
search: ChampionSearch::new(""),
|
||||
searching: false,
|
||||
input: cx.new(|cx| InputState::new(window, cx).placeholder("Rechercher")),
|
||||
periods: periods(seasons),
|
||||
}
|
||||
}
|
||||
|
||||
/// The period of `season`; none for a Season the table does not know.
|
||||
fn period(&self, season: &str) -> Range<i64> {
|
||||
(self.periods.iter())
|
||||
.find(|(name, _)| name == season)
|
||||
.map_or(0..0, |(_, period)| period.clone())
|
||||
}
|
||||
}
|
||||
|
||||
/// Each Season's period in epoch ms: from its start to the next one's, the last open-ended.
|
||||
/// `seasons` is sorted by start.
|
||||
fn periods(seasons: &[Season]) -> Vec<(String, Range<i64>)> {
|
||||
(seasons.iter().enumerate())
|
||||
.map(|(ix, season)| {
|
||||
let end = seasons
|
||||
.get(ix + 1)
|
||||
.map_or(i64::MAX, |next| next.start.start_ms());
|
||||
(season.name.clone(), season.start.start_ms()..end)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
impl Page {
|
||||
/// The positions, in the entries, of the Matches the filters keep.
|
||||
fn visible_matches(&self, champions: &Champions) -> Vec<usize> {
|
||||
let filters = &self.matches.filters;
|
||||
let period = match &self.season {
|
||||
SeasonScope::AllSeasons => None,
|
||||
SeasonScope::Season(name) => Some(filters.period(name)),
|
||||
};
|
||||
(self.matches.entries.iter().flatten())
|
||||
.enumerate()
|
||||
.filter(|(_, entry)| {
|
||||
period
|
||||
.as_ref()
|
||||
.is_none_or(|p| p.contains(&entry.started_at_ms))
|
||||
&& self.format.is_none_or(|format| entry.format == format)
|
||||
&& filters.placement.keeps(entry)
|
||||
&& (!filters.searching
|
||||
|| champions.found_by(
|
||||
&filters.search,
|
||||
entry.champion_id,
|
||||
&entry.champion_name,
|
||||
))
|
||||
})
|
||||
.map(|(ix, _)| ix)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Keeps the Matches the filters leave and writes them to the list. The Match chosen stays
|
||||
/// while it is left; else the first one is chosen, or none when none is.
|
||||
pub(super) fn refilter(&mut self, champions: &Champions, cx: &mut Context<Self>) {
|
||||
let visible = self.visible_matches(champions);
|
||||
let matches = &mut self.matches;
|
||||
let entries = matches.entries.as_deref().unwrap_or_default();
|
||||
let kept = (matches.selected.as_deref())
|
||||
.is_some_and(|id| visible.iter().any(|&ix| entries[ix].match_id == id));
|
||||
let first = visible.first().map(|&ix| entries[ix].match_id.clone());
|
||||
let rows: Vec<MatchRow> = (visible.iter().map(|&ix| &entries[ix]))
|
||||
.map(|entry| MatchRow {
|
||||
match_id: entry.match_id.clone(),
|
||||
champion: champions.name(entry.champion_id, &entry.champion_name),
|
||||
portrait: champions.portrait(entry.champion_id),
|
||||
when: entry.when.clone().into(),
|
||||
placement: ordinal(entry.placement).into(),
|
||||
provisional: entry.provisional,
|
||||
})
|
||||
.collect();
|
||||
matches.visible = visible;
|
||||
let choose = !kept && (first.is_some() || matches.selected.is_some());
|
||||
if choose {
|
||||
matches.selected = first;
|
||||
}
|
||||
let selected = matches.selected.clone();
|
||||
matches
|
||||
.list
|
||||
.update(cx, |list, cx| list.set_rows(rows, selected.as_deref(), cx));
|
||||
if choose {
|
||||
self.request_recap();
|
||||
}
|
||||
}
|
||||
|
||||
/// A filter of this page changed: the list follows while it shows.
|
||||
fn filtered(&mut self, cx: &mut Context<Self>) {
|
||||
if self.shown_tab == Tab::Matches || self.tab == Tab::Matches {
|
||||
let champions = self.champions();
|
||||
self.refilter(&champions, cx);
|
||||
}
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn choose_placement(&mut self, placement: PlacementFilter, cx: &mut Context<Self>) {
|
||||
if self.matches.filters.placement != placement {
|
||||
self.matches.filters.placement = placement;
|
||||
self.filtered(cx);
|
||||
}
|
||||
}
|
||||
|
||||
/// The search field's text changed.
|
||||
pub(super) fn matches_searched(&mut self, cx: &mut Context<Self>) {
|
||||
let query = self.matches.filters.input.read(cx).value();
|
||||
let filters = &mut self.matches.filters;
|
||||
filters.search = ChampionSearch::new(&query);
|
||||
filters.searching = !query.is_empty();
|
||||
self.filtered(cx);
|
||||
}
|
||||
|
||||
/// Above the list: the Season and Format of « Statistiques » (the same selectors), the
|
||||
/// Placement and the search. Plain elements of the page, a few of them.
|
||||
pub(super) fn matches_filters(&self, cx: &mut Context<Page>) -> impl IntoElement {
|
||||
div()
|
||||
.v_flex()
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.h_flex()
|
||||
.gap_2()
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.debug_selector(|| "matches-season".into())
|
||||
.child(
|
||||
Select::new(&self.season_select)
|
||||
.id("season")
|
||||
.w_full()
|
||||
.min_w_0(),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.debug_selector(|| "matches-format".into())
|
||||
.child(
|
||||
Select::new(&self.format_select)
|
||||
.id("format")
|
||||
.w_full()
|
||||
.min_w_0(),
|
||||
),
|
||||
),
|
||||
)
|
||||
.child(self.placement_control(cx))
|
||||
.child(
|
||||
Input::new(&self.matches.filters.input)
|
||||
.cleanable(true)
|
||||
.w_full(),
|
||||
)
|
||||
}
|
||||
|
||||
/// The segmented control « Tous · Top 1 · Victoires ».
|
||||
fn placement_control(&self, cx: &mut Context<Page>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let (ring, border, muted, active, active_foreground) = (
|
||||
theme.ring,
|
||||
theme.border,
|
||||
theme.tab_foreground,
|
||||
theme.tab_active,
|
||||
theme.tab_active_foreground,
|
||||
);
|
||||
let (hover, hover_foreground) = (theme.accent, theme.accent_foreground);
|
||||
let chosen = self.matches.filters.placement;
|
||||
div()
|
||||
.h_flex()
|
||||
.gap_1()
|
||||
.p(px(2.))
|
||||
.rounded_md()
|
||||
.border_1()
|
||||
.border_color(border)
|
||||
.children(PLACEMENTS.map(|(id, label, placement)| {
|
||||
let current = chosen == placement;
|
||||
BaseButton::new(id)
|
||||
.flex_1()
|
||||
.h_flex()
|
||||
.justify_center()
|
||||
.py_1()
|
||||
.rounded_md()
|
||||
.text_sm()
|
||||
.font_weight(FontWeight::SEMIBOLD)
|
||||
// Always bordered, so the focus ring does not shift the label.
|
||||
.border_1()
|
||||
.border_color(transparent_black())
|
||||
.focus_visible(|style| {
|
||||
style.border_color(if current { active_foreground } else { ring })
|
||||
})
|
||||
.text_color(if current { active_foreground } else { muted })
|
||||
.when(current, |button| button.bg(active))
|
||||
.when(!current, |button| {
|
||||
button.hover(|style| style.bg(hover).text_color(hover_foreground))
|
||||
})
|
||||
.accessibility_label(label)
|
||||
.debug_selector(move || id.into())
|
||||
.child(label)
|
||||
.on_click(
|
||||
cx.listener(move |page, _, _, cx| page.choose_placement(placement, cx)),
|
||||
)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
/// What the list says when the filters leave no Match, over the empty list.
|
||||
pub(super) fn no_result(muted: Hsla) -> impl IntoElement {
|
||||
div()
|
||||
.absolute()
|
||||
.top_0()
|
||||
.left_0()
|
||||
.right_0()
|
||||
.p_4()
|
||||
.text_sm()
|
||||
.text_color(muted)
|
||||
.debug_selector(|| "matches-no-result".into())
|
||||
.child(NO_RESULT)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{MatchEntry, PlacementFilter, Season, periods};
|
||||
use arena_tracker_core::{Date, Format};
|
||||
|
||||
fn entry(placement: u8, win: bool) -> MatchEntry {
|
||||
MatchEntry {
|
||||
match_id: "EUW1_1".into(),
|
||||
champion_id: 1,
|
||||
champion_name: "Annie".into(),
|
||||
started_at_ms: 0,
|
||||
when: String::new(),
|
||||
placement,
|
||||
provisional: false,
|
||||
format: Format::Arena3x6,
|
||||
win,
|
||||
}
|
||||
}
|
||||
|
||||
fn season(name: &str, month: u8) -> Season {
|
||||
Season {
|
||||
name: name.into(),
|
||||
start: Date {
|
||||
year: 2026,
|
||||
month,
|
||||
day: 1,
|
||||
},
|
||||
official_track: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn top_1_is_a_first_place_and_a_win_is_the_games_own() {
|
||||
// A 2nd place is a win in Arena 3x6, a 4th is not, and a 1st is both.
|
||||
let (first, second, fourth) = (entry(1, true), entry(2, true), entry(4, false));
|
||||
let kept =
|
||||
|filter: PlacementFilter| [&first, &second, &fourth].map(|entry| filter.keeps(entry));
|
||||
assert_eq!(kept(PlacementFilter::All), [true; 3]);
|
||||
assert_eq!(kept(PlacementFilter::Top1), [true, false, false]);
|
||||
assert_eq!(kept(PlacementFilter::Wins), [true, true, false]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_season_runs_to_the_next_ones_start_and_the_last_is_open() {
|
||||
let (a, b) = (season("A", 1), season("B", 6));
|
||||
let periods = periods(&[a.clone(), b.clone()]);
|
||||
assert_eq!(periods[0].1, a.start.start_ms()..b.start.start_ms());
|
||||
assert_eq!(periods[1].1.end, i64::MAX);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
//! How « Parties » is laid out: the place of the banner, then the list and the recap side by
|
||||
//! side, or the list behind a button in a narrow window.
|
||||
|
||||
use super::filters::no_result;
|
||||
use super::{Recap, recap};
|
||||
use crate::card_images;
|
||||
use crate::page::Page;
|
||||
@@ -72,21 +73,40 @@ impl Page {
|
||||
/// The list (≈ 320 px) and the recap; narrower than `NARROW`, the list opens over the
|
||||
/// recap from a button.
|
||||
fn matches_split(&self, window: &mut Window, cx: &mut Context<Page>) -> AnyElement {
|
||||
let theme = cx.theme();
|
||||
let narrow = window.viewport_size().width < px(NARROW);
|
||||
let theme = cx.theme();
|
||||
let (background, border, radius, muted) = (
|
||||
theme.background,
|
||||
theme.border,
|
||||
theme.radius,
|
||||
theme.muted_foreground,
|
||||
);
|
||||
let none = self.matches.visible.is_empty();
|
||||
let list = div()
|
||||
.v_flex()
|
||||
.w(px(LIST_WIDTH))
|
||||
.max_w_full()
|
||||
.flex_shrink_0()
|
||||
.h_full()
|
||||
.overflow_hidden()
|
||||
.bg(theme.background)
|
||||
.border_1()
|
||||
.border_color(theme.border)
|
||||
.rounded(theme.radius)
|
||||
// A cached view: the page drawn again (the veil, the recap arriving) does not draw
|
||||
// the list.
|
||||
.child((self.matches.list.clone()).cached(StyleRefinement::default().size_full()));
|
||||
.gap_2()
|
||||
.child(self.matches_filters(cx))
|
||||
.child(
|
||||
div()
|
||||
.relative()
|
||||
.flex_1()
|
||||
.min_h_0()
|
||||
.overflow_hidden()
|
||||
.bg(background)
|
||||
.border_1()
|
||||
.border_color(border)
|
||||
.rounded(radius)
|
||||
// A cached view: the page drawn again (the veil, the recap arriving) does
|
||||
// not draw the list.
|
||||
.child(
|
||||
(self.matches.list.clone()).cached(StyleRefinement::default().size_full()),
|
||||
)
|
||||
.when(none, |area| area.child(no_result(muted))),
|
||||
);
|
||||
let recap = div()
|
||||
.id("recap-scroll")
|
||||
.flex_1()
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use arena_tracker_core::{MatchRecap, RecapPlayer, Statistics};
|
||||
use arena_tracker_core::{Champion, ChampionSearch, MatchRecap, RecapPlayer, Statistics};
|
||||
use gpui_kit::SharedString;
|
||||
|
||||
use super::details::Details;
|
||||
@@ -16,9 +16,17 @@ pub(in crate::page) const UNAVAILABLE: &str = "Indisponible";
|
||||
/// The same in a Provisional Match, whose source gives less until Riot publishes it.
|
||||
pub(in crate::page) const PENDING: &str = "En attente";
|
||||
|
||||
/// A champion of the catalog, as « Parties » needs it.
|
||||
struct Known {
|
||||
champion: Champion,
|
||||
/// The catalog's name, shared with every row that shows it.
|
||||
name: SharedString,
|
||||
portrait: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// The catalog's name and square portrait of each champion, by id.
|
||||
#[derive(Default)]
|
||||
pub(in crate::page) struct Champions(HashMap<u32, (SharedString, Option<PathBuf>)>);
|
||||
pub(in crate::page) struct Champions(HashMap<u32, Known>);
|
||||
|
||||
impl Champions {
|
||||
/// From statistics, whose rows hold every champion of the catalog whatever their scope.
|
||||
@@ -26,8 +34,12 @@ impl Champions {
|
||||
Champions(
|
||||
(stats.iter().flat_map(|s| s.rows.iter()))
|
||||
.map(|row| {
|
||||
let name = SharedString::from(row.champion.name.clone());
|
||||
(row.champion.id, (name, row.portrait.clone()))
|
||||
let known = Known {
|
||||
champion: row.champion.clone(),
|
||||
name: SharedString::from(row.champion.name.clone()),
|
||||
portrait: row.portrait.clone(),
|
||||
};
|
||||
(row.champion.id, known)
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
@@ -37,11 +49,24 @@ impl Champions {
|
||||
pub(in crate::page) fn name(&self, id: u32, fallback: &str) -> SharedString {
|
||||
self.0
|
||||
.get(&id)
|
||||
.map_or_else(|| fallback.to_string().into(), |(name, _)| name.clone())
|
||||
.map_or_else(|| fallback.to_string().into(), |known| known.name.clone())
|
||||
}
|
||||
|
||||
pub(in crate::page) fn portrait(&self, id: u32) -> Option<PathBuf> {
|
||||
self.0.get(&id).and_then(|(_, portrait)| portrait.clone())
|
||||
self.0.get(&id).and_then(|known| known.portrait.clone())
|
||||
}
|
||||
|
||||
/// Whether the search finds the champion, by the catalog's names and aliases. Without the
|
||||
/// catalog, the Match's own name is Riot's key, which the aliases are keyed by.
|
||||
pub(in crate::page) fn found_by(&self, search: &ChampionSearch, id: u32, key: &str) -> bool {
|
||||
match self.0.get(&id) {
|
||||
Some(known) => search.matches(&known.champion),
|
||||
None => search.matches(&Champion {
|
||||
id,
|
||||
key: key.into(),
|
||||
name: key.into(),
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,11 +36,11 @@ impl Page {
|
||||
following,
|
||||
champion_sort,
|
||||
} = launch;
|
||||
let seasons: Vec<SharedString> = tracker
|
||||
.seasons()
|
||||
.into_iter()
|
||||
let season_table = tracker.seasons();
|
||||
let seasons: Vec<SharedString> = season_table
|
||||
.iter()
|
||||
.rev()
|
||||
.map(|s| s.name.into())
|
||||
.map(|s| s.name.clone().into())
|
||||
.chain([ALL_SEASONS.into()])
|
||||
.collect();
|
||||
let current_season = tracker.current_season(now_ms()).map(|s| s.name);
|
||||
@@ -85,7 +85,7 @@ impl Page {
|
||||
let ring = cx.new(|_| Ring::new());
|
||||
let banner_art = BannerArt::new(cx);
|
||||
let others_hover = Self::light_and_reveal(&others_grid, cx);
|
||||
let matches = super::matches::Matches::new(cx);
|
||||
let matches = super::matches::Matches::new(&season_table, window, cx);
|
||||
|
||||
let mut subscriptions = Vec::new();
|
||||
subscriptions.extend(Self::light_on_hover(&home_grid, cx));
|
||||
|
||||
@@ -16,6 +16,7 @@ mod key_fixtures;
|
||||
mod match_animation;
|
||||
mod matches;
|
||||
mod matches_details;
|
||||
mod matches_filters;
|
||||
mod matches_fixtures;
|
||||
mod navigation;
|
||||
mod page_fixtures;
|
||||
|
||||
@@ -0,0 +1,327 @@
|
||||
//! The filters of « Parties »: Season and Format shared with « Statistiques », Placement and the
|
||||
//! champion search, alone and together.
|
||||
|
||||
use super::matches_fixtures::{MORE, chosen, listed, recap_id, recap_ready, tracker_in};
|
||||
use super::page_fixtures::{
|
||||
assert_at_rest, center, draw, open_page_with_tracker, show, statistics, switch_tab,
|
||||
};
|
||||
use crate::champion_table::tests::row;
|
||||
use crate::page::{ALL_FORMATS, ALL_SEASONS, Page, Tab};
|
||||
use arena_tracker_core::{Champion, Date, Format, Season, SeasonScope};
|
||||
use gpui_kit::component::select::SelectEvent;
|
||||
use gpui_kit::{Entity, Modifiers, TestAppContext, VisualTestContext, px, size};
|
||||
|
||||
/// The Season table: « Saison 1 » from 1 Jan. 2026, « Saison 2 » from 1 Sept. 2026, the
|
||||
/// current one.
|
||||
fn seasons() -> Vec<Season> {
|
||||
[("Saison 1", 1), ("Saison 2", 9)]
|
||||
.map(|(name, month)| Season {
|
||||
name: name.into(),
|
||||
start: Date {
|
||||
year: 2026,
|
||||
month,
|
||||
day: 1,
|
||||
},
|
||||
official_track: None,
|
||||
})
|
||||
.to_vec()
|
||||
}
|
||||
|
||||
/// « Parties » opened on Alice's five Matches, once its list and the recap are there.
|
||||
async fn open(cx: &mut TestAppContext, seasons: Vec<Season>) -> (Entity<Page>, VisualTestContext) {
|
||||
cx.executor().allow_parking();
|
||||
let (page, mut window) = open_page_with_tracker(cx, tracker_in(true, seasons).0);
|
||||
switch_tab(&page, &mut window, Tab::Matches);
|
||||
recap_ready(&page, cx).await;
|
||||
draw(&mut window);
|
||||
(page, window)
|
||||
}
|
||||
|
||||
fn click(cx: &mut VisualTestContext, id: &'static str) {
|
||||
let at = center(cx, id);
|
||||
cx.simulate_click(at, Modifiers::none());
|
||||
draw(cx);
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum Selector {
|
||||
Season,
|
||||
Format,
|
||||
}
|
||||
|
||||
/// The player picks `label` in the Season or Format selector, of whichever page shows it.
|
||||
fn pick(page: &Entity<Page>, cx: &mut VisualTestContext, selector: Selector, label: &str) {
|
||||
let select = page.read_with(cx, |p, _| match selector {
|
||||
Selector::Season => p.season_select.clone(),
|
||||
Selector::Format => p.format_select.clone(),
|
||||
});
|
||||
let label = label.to_string();
|
||||
cx.update(|_, cx| {
|
||||
select.update(cx, |_, cx| {
|
||||
cx.emit(SelectEvent::Confirm(Some(label.into())))
|
||||
})
|
||||
});
|
||||
draw(cx);
|
||||
}
|
||||
|
||||
/// The player types `text` in the search field of « Parties », whose text is replaced.
|
||||
fn search(page: &Entity<Page>, cx: &mut VisualTestContext, text: &str) {
|
||||
let input = page.read_with(cx, |p, _| p.matches.search_input().clone());
|
||||
cx.update(|window, cx| {
|
||||
input.update(cx, |input, cx| {
|
||||
input.focus(window, cx);
|
||||
input.clean(window, cx);
|
||||
})
|
||||
});
|
||||
if !text.is_empty() {
|
||||
cx.simulate_input(text);
|
||||
}
|
||||
draw(cx);
|
||||
}
|
||||
|
||||
/// The ids of `MORE` at these positions.
|
||||
fn some(positions: &[usize]) -> Vec<&'static str> {
|
||||
positions.iter().map(|&ix| MORE[ix]).collect()
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_current_season_is_the_default_and_the_list_is_that_seasons(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open(cx, seasons()).await;
|
||||
let cx = &mut window;
|
||||
page.read_with(cx, |p, cx| {
|
||||
assert_eq!(p.season, SeasonScope::Season("Saison 2".into()));
|
||||
let selected = p.season_select.read(cx).selected_value();
|
||||
assert_eq!(selected.map(|s| s.as_ref()), Some("Saison 2"));
|
||||
});
|
||||
assert_eq!(listed(&page, cx), some(&[0, 1, 2]));
|
||||
// The most recent of them is chosen and its recap shown.
|
||||
assert_eq!(chosen(&page, cx).as_deref(), Some(MORE[0]));
|
||||
assert_eq!(recap_id(&page, cx).as_deref(), Some(MORE[0]));
|
||||
for id in [
|
||||
"matches-season",
|
||||
"matches-format",
|
||||
"matches-placement-all",
|
||||
"matches-placement-top1",
|
||||
"matches-placement-wins",
|
||||
] {
|
||||
assert!(cx.debug_bounds(id).is_some(), "{id}");
|
||||
}
|
||||
assert!(cx.debug_bounds("matches-no-result").is_none());
|
||||
// The filters are above the list, within its column.
|
||||
let (season, format, rows) = (
|
||||
cx.debug_bounds("matches-season").unwrap(),
|
||||
cx.debug_bounds("matches-format").unwrap(),
|
||||
cx.debug_bounds("match-list").unwrap(),
|
||||
);
|
||||
let placement = cx.debug_bounds("matches-placement-all").unwrap();
|
||||
assert!(season.bottom() <= placement.top() && placement.bottom() <= rows.top());
|
||||
// Within the list's column (the list's border is 1 px).
|
||||
assert!(season.right() <= format.left() && format.right() <= rows.right() + px(1.));
|
||||
assert!(season.left() + px(1.) >= rows.left());
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn without_a_current_season_every_season_is_listed(cx: &mut TestAppContext) {
|
||||
// The only Season of the table starts in 2099.
|
||||
let future = Season {
|
||||
name: "Saison lointaine".into(),
|
||||
start: Date {
|
||||
year: 2099,
|
||||
month: 1,
|
||||
day: 1,
|
||||
},
|
||||
official_track: None,
|
||||
};
|
||||
let (page, mut window) = open(cx, vec![future]).await;
|
||||
let cx = &mut window;
|
||||
page.read_with(cx, |p, cx| {
|
||||
assert_eq!(p.season, SeasonScope::AllSeasons);
|
||||
let selected = p.season_select.read(cx).selected_value();
|
||||
assert_eq!(selected.map(|s| s.as_ref()), Some(ALL_SEASONS));
|
||||
});
|
||||
assert_eq!(listed(&page, cx), MORE);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_season_alone_keeps_the_matches_of_its_period(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open(cx, seasons()).await;
|
||||
let cx = &mut window;
|
||||
pick(&page, cx, Selector::Season, "Saison 1");
|
||||
assert_eq!(listed(&page, cx), some(&[3, 4]));
|
||||
// The Match chosen is not kept: the first one shown is, and its recap follows.
|
||||
assert_eq!(chosen(&page, cx).as_deref(), Some(MORE[3]));
|
||||
recap_ready(&page, cx).await;
|
||||
assert_eq!(recap_id(&page, cx).as_deref(), Some(MORE[3]));
|
||||
|
||||
pick(&page, cx, Selector::Season, ALL_SEASONS);
|
||||
assert_eq!(listed(&page, cx), MORE);
|
||||
// Listed and kept again: the choice stays.
|
||||
assert_eq!(chosen(&page, cx).as_deref(), Some(MORE[3]));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_format_alone_keeps_its_matches(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open(cx, Vec::new()).await;
|
||||
let cx = &mut window;
|
||||
assert_eq!(listed(&page, cx), MORE);
|
||||
pick(&page, cx, Selector::Format, &Format::BraveryArena.name());
|
||||
assert_eq!(listed(&page, cx), some(&[1]));
|
||||
assert_eq!(chosen(&page, cx).as_deref(), Some(MORE[1]));
|
||||
pick(&page, cx, Selector::Format, &Format::Arena3x6.name());
|
||||
assert_eq!(listed(&page, cx), some(&[0, 2, 3, 4]));
|
||||
pick(&page, cx, Selector::Format, ALL_FORMATS);
|
||||
assert_eq!(listed(&page, cx), MORE);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_placement_alone_keeps_top_1_or_the_wins(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open(cx, Vec::new()).await;
|
||||
let cx = &mut window;
|
||||
click(cx, "matches-placement-top1");
|
||||
assert_eq!(listed(&page, cx), some(&[1]));
|
||||
assert_eq!(chosen(&page, cx).as_deref(), Some(MORE[1]));
|
||||
// A 2nd place is a Win in Arena 3x6, a 5th is not.
|
||||
click(cx, "matches-placement-wins");
|
||||
assert_eq!(listed(&page, cx), some(&[0, 1, 2, 4]));
|
||||
// Listed: the choice stays.
|
||||
assert_eq!(chosen(&page, cx).as_deref(), Some(MORE[1]));
|
||||
click(cx, "matches-placement-all");
|
||||
assert_eq!(listed(&page, cx), MORE);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_search_finds_a_champion_by_name_or_alias(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open(cx, Vec::new()).await;
|
||||
let cx = &mut window;
|
||||
// No catalog yet: the Match's own name, Riot's key, which the aliases are keyed by.
|
||||
search(&page, cx, "tf");
|
||||
assert_eq!(listed(&page, cx), some(&[3]));
|
||||
assert_eq!(chosen(&page, cx).as_deref(), Some(MORE[3]));
|
||||
search(&page, cx, "IREL");
|
||||
assert_eq!(listed(&page, cx), some(&[0, 1, 4]));
|
||||
// The catalog's French name finds it too, and a field emptied lists every Match.
|
||||
let mut fate = row("Twisted Fate");
|
||||
fate.champion = Champion {
|
||||
id: 4,
|
||||
key: "TwistedFate".into(),
|
||||
name: "Destin Tordu".into(),
|
||||
};
|
||||
show(&page, cx, statistics(0, 1, vec![fate]));
|
||||
search(&page, cx, "tordu");
|
||||
assert_eq!(listed(&page, cx), some(&[3]));
|
||||
page.read_with(cx, |p, cx| {
|
||||
assert_eq!(p.matches.list.read(cx).rows()[0].champion, "Destin Tordu");
|
||||
});
|
||||
search(&page, cx, "");
|
||||
assert_eq!(listed(&page, cx), MORE);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_filters_combine_and_say_when_nothing_matches(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open(cx, seasons()).await;
|
||||
let cx = &mut window;
|
||||
assert_eq!(listed(&page, cx), some(&[0, 1, 2]));
|
||||
click(cx, "matches-placement-wins");
|
||||
search(&page, cx, "irelia");
|
||||
assert_eq!(listed(&page, cx), some(&[0, 1]));
|
||||
click(cx, "matches-placement-top1");
|
||||
assert_eq!(listed(&page, cx), some(&[1]));
|
||||
pick(&page, cx, Selector::Format, &Format::BraveryArena.name());
|
||||
assert_eq!(listed(&page, cx), some(&[1]));
|
||||
assert!(cx.debug_bounds("matches-no-result").is_none());
|
||||
|
||||
// Not in the other Season: nothing is left, the list says so and the recap goes.
|
||||
pick(&page, cx, Selector::Season, "Saison 1");
|
||||
assert!(listed(&page, cx).is_empty());
|
||||
assert_eq!(chosen(&page, cx), None);
|
||||
assert_eq!(recap_id(&page, cx), None);
|
||||
assert!(cx.debug_bounds("matches-no-result").is_some());
|
||||
// The filters stay on screen to be changed.
|
||||
assert!(cx.debug_bounds("matches-placement-all").is_some());
|
||||
page.read_with(cx, |p, _| {
|
||||
assert!(matches!(p.matches.recap, crate::page::matches::Recap::None))
|
||||
});
|
||||
|
||||
// Loosening one brings the Matches, and the first is chosen.
|
||||
pick(&page, cx, Selector::Season, ALL_SEASONS);
|
||||
assert_eq!(listed(&page, cx), some(&[1]));
|
||||
assert!(cx.debug_bounds("matches-no-result").is_none());
|
||||
assert_eq!(chosen(&page, cx).as_deref(), Some(MORE[1]));
|
||||
recap_ready(&page, cx).await;
|
||||
assert_eq!(recap_id(&page, cx).as_deref(), Some(MORE[1]));
|
||||
assert_at_rest(cx);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn season_and_format_are_the_statistics_pages_and_back(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open(cx, seasons()).await;
|
||||
let cx = &mut window;
|
||||
let scope = |page: &Entity<Page>, cx: &mut VisualTestContext| {
|
||||
page.read_with(cx, |p, _| (p.season.clone(), p.format))
|
||||
};
|
||||
// From « Parties » to « Statistiques ».
|
||||
pick(&page, cx, Selector::Season, "Saison 1");
|
||||
pick(&page, cx, Selector::Format, &Format::Arena3x6.name());
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
draw(cx);
|
||||
assert_eq!(
|
||||
scope(&page, cx),
|
||||
(
|
||||
SeasonScope::Season("Saison 1".into()),
|
||||
Some(Format::Arena3x6)
|
||||
)
|
||||
);
|
||||
assert!(cx.debug_bounds("matches-season").is_none());
|
||||
|
||||
// From « Statistiques » to « Parties ».
|
||||
pick(&page, cx, Selector::Season, ALL_SEASONS);
|
||||
pick(&page, cx, Selector::Format, ALL_FORMATS);
|
||||
pick(&page, cx, Selector::Format, &Format::BraveryArena.name());
|
||||
switch_tab(&page, cx, Tab::Matches);
|
||||
assert_eq!(
|
||||
scope(&page, cx),
|
||||
(SeasonScope::AllSeasons, Some(Format::BraveryArena))
|
||||
);
|
||||
assert_eq!(listed(&page, cx), some(&[1]));
|
||||
assert_eq!(chosen(&page, cx).as_deref(), Some(MORE[1]));
|
||||
// Placement and search are not « Statistiques »: it keeps its own.
|
||||
click(cx, "matches-placement-top1");
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
assert_eq!(
|
||||
page.read_with(cx, |p, _| p.filter),
|
||||
arena_tracker_core::StateFilter::All
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_filters_are_with_the_list_in_a_narrow_window(cx: &mut TestAppContext) {
|
||||
let (page, mut window) = open(cx, Vec::new()).await;
|
||||
let cx = &mut window;
|
||||
cx.simulate_resize(size(px(800.), px(700.)));
|
||||
draw(cx);
|
||||
assert!(cx.debug_bounds("matches-placement-top1").is_none());
|
||||
click(cx, "matches-list-toggle");
|
||||
assert!(cx.debug_bounds("matches-placement-top1").is_some());
|
||||
click(cx, "matches-placement-top1");
|
||||
assert_eq!(listed(&page, cx), some(&[1]));
|
||||
// The filters stay open for another choice: only a Match closes the list.
|
||||
assert!(cx.debug_bounds("matches-list-over").is_some());
|
||||
click(cx, "match-row-0");
|
||||
assert!(cx.debug_bounds("matches-list-over").is_none());
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
async fn the_filters_are_kept_from_one_opening_to_the_next_but_not_the_choice(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
let (page, mut window) = open(cx, Vec::new()).await;
|
||||
let cx = &mut window;
|
||||
click(cx, "matches-placement-wins");
|
||||
search(&page, cx, "irelia");
|
||||
assert_eq!(listed(&page, cx), some(&[0, 1, 4]));
|
||||
click(cx, "match-row-2");
|
||||
switch_tab(&page, cx, Tab::Challenge);
|
||||
switch_tab(&page, cx, Tab::Matches);
|
||||
assert_eq!(listed(&page, cx), some(&[0, 1, 4]));
|
||||
assert_eq!(chosen(&page, cx).as_deref(), Some(MORE[0]));
|
||||
}
|
||||
@@ -4,7 +4,7 @@ use crate::page::{Page, Tab};
|
||||
use crate::worker::Msg;
|
||||
use arena_tracker_core::{
|
||||
Account, ChampSelect, ClientError, ClientEvent, GameClientSource, Gameflow, MatchHistorySource,
|
||||
SourceError, Tracker,
|
||||
Season, SourceError, Tracker,
|
||||
};
|
||||
use gpui_kit::{Entity, TestAppContext, VisualTestContext};
|
||||
use std::path::Path;
|
||||
@@ -20,9 +20,34 @@ pub(super) const RECAP_1750: &str =
|
||||
pub(super) const ALICE: [&str; 3] = ["EUW1_9000000006", "EUW1_9000000008", "EUW1_9000000007"];
|
||||
/// Bob's only Match.
|
||||
pub(super) const BOB: &str = "EUW1_9000000009";
|
||||
/// Alice's Matches with two more, newest first: `MORE[1]` is Irelia in Bravery Arena on 14 Oct.
|
||||
/// 2026 (1st), `MORE[3]` Twisted Fate on 29 Aug. 2026 (5th, not a Win); the others are `ALICE`.
|
||||
pub(super) const MORE: [&str; 5] = [
|
||||
"EUW1_9000000006",
|
||||
"EUW1_9000000010",
|
||||
"EUW1_9000000008",
|
||||
"EUW1_9000000011",
|
||||
"EUW1_9000000007",
|
||||
];
|
||||
|
||||
/// Alice and Bob, each with their Arena 3x6 Matches, made from the core's Match-V5 fixtures.
|
||||
pub(super) struct TwoAccounts;
|
||||
/// Alice and Bob, each with their Arena 3x6 Matches, made from the core's Match-V5 fixtures;
|
||||
/// `more`: Alice has the two more of `MORE`.
|
||||
pub(super) struct TwoAccounts {
|
||||
pub(super) more: bool,
|
||||
}
|
||||
|
||||
/// The Match of `json` with the Account ending `placement`th, a Win or not.
|
||||
fn placed(json: &str, placement: u8, win: bool) -> String {
|
||||
let (head, account) = json.split_at(json.find("\"puuid\": \"fixture-puuid-self\"").unwrap());
|
||||
let account = account
|
||||
.replacen(
|
||||
"\"placement\": 2,\n \"subteamPlacement\": 2,",
|
||||
&format!("\"placement\": {placement},\n \"subteamPlacement\": {placement},"),
|
||||
1,
|
||||
)
|
||||
.replacen("\"win\": true", &format!("\"win\": {win}"), 1);
|
||||
format!("{head}{account}")
|
||||
}
|
||||
|
||||
impl MatchHistorySource for TwoAccounts {
|
||||
fn resolve_account(&self, game_name: &str, tag_line: &str) -> Result<Account, SourceError> {
|
||||
@@ -45,6 +70,7 @@ impl MatchHistorySource for TwoAccounts {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
Ok(match puuid {
|
||||
"Alice" if self.more => MORE.map(String::from).to_vec(),
|
||||
"Alice" => ALICE.map(String::from).to_vec(),
|
||||
"Bob" => vec![BOB.into()],
|
||||
_ => Vec::new(),
|
||||
@@ -60,6 +86,16 @@ impl MatchHistorySource for TwoAccounts {
|
||||
Ok(match id {
|
||||
"EUW1_9000000006" => MATCH_1750.replace("fixture-puuid-self", "Alice"),
|
||||
"EUW1_9000000007" => RECAP_1750.replace("fixture-puuid-self", "Alice"),
|
||||
"EUW1_9000000010" => placed(&other("1792000000000"), 1, true)
|
||||
.replace("\"queueId\": 1750", "\"queueId\": 1740")
|
||||
.replace("fixture-puuid-self", "Alice"),
|
||||
"EUW1_9000000011" => placed(&other("1788000000000"), 5, false)
|
||||
.replace("\"championId\": 39,", "\"championId\": 4,")
|
||||
.replace(
|
||||
"\"championName\": \"Irelia\"",
|
||||
"\"championName\": \"TwistedFate\"",
|
||||
)
|
||||
.replace("fixture-puuid-self", "Alice"),
|
||||
"EUW1_9000000008" => other("1790000000000")
|
||||
.replace("\"championId\": 39,", "\"championId\": 103,")
|
||||
.replace("\"championName\": \"Irelia\"", "\"championName\": \"Ahri\"")
|
||||
@@ -97,10 +133,15 @@ impl GameClientSource for Lobby {
|
||||
/// A tracker that knows both Accounts, Alice signed in to the client; the name signs another
|
||||
/// one in.
|
||||
pub(super) fn tracker() -> (Tracker, Arc<Mutex<String>>) {
|
||||
tracker_in(false, Vec::new())
|
||||
}
|
||||
|
||||
/// The same with the Season table `seasons`, and `more` of Alice's Matches.
|
||||
pub(super) fn tracker_in(more: bool, seasons: Vec<Season>) -> (Tracker, Arc<Mutex<String>>) {
|
||||
let signed_in = Arc::new(Mutex::new("Alice".to_string()));
|
||||
let tracker = Tracker::open(Path::new(":memory:"), Box::new(TwoAccounts))
|
||||
let tracker = Tracker::open(Path::new(":memory:"), Box::new(TwoAccounts { more }))
|
||||
.unwrap()
|
||||
.with_seasons(Vec::new())
|
||||
.with_seasons(seasons)
|
||||
.with_client(Box::new(Lobby(signed_in.clone())));
|
||||
tracker.sync("Bob#EUW", &mut |_| {}).unwrap();
|
||||
tracker.follow_client(0, None, &mut |_| {});
|
||||
|
||||
@@ -24,8 +24,10 @@ pub struct MatchEntry {
|
||||
pub when: String,
|
||||
pub placement: u8,
|
||||
pub provisional: bool,
|
||||
/// Not in the row: kept for the filters to come.
|
||||
/// Not in the row: what the filters of « Parties » read, on the rows already loaded.
|
||||
pub format: Format,
|
||||
/// The game's own Win (« Victoires »).
|
||||
pub win: bool,
|
||||
}
|
||||
|
||||
/// The stored Matches of `puuid`, newest first.
|
||||
@@ -46,6 +48,7 @@ pub fn match_list(tracker: &Tracker, puuid: &str) -> Result<Vec<MatchEntry>, Str
|
||||
placement: m.placement,
|
||||
provisional: m.provisional,
|
||||
format: m.format,
|
||||
win: m.win,
|
||||
})
|
||||
.collect())
|
||||
}
|
||||
@@ -85,7 +88,7 @@ pub fn spawn_recap(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::match_list;
|
||||
use arena_tracker_core::{Account, MatchHistorySource, SourceError, Tracker};
|
||||
use arena_tracker_core::{Account, Format, MatchHistorySource, SourceError, Tracker};
|
||||
use std::path::Path;
|
||||
|
||||
const MATCH: &str =
|
||||
@@ -136,6 +139,8 @@ mod tests {
|
||||
let ids: Vec<_> = list.iter().map(|m| m.match_id.as_str()).collect();
|
||||
assert_eq!(ids, ["EUW1_9000000006", "EUW1_9000000007"]);
|
||||
assert_eq!(list[0].placement, 2);
|
||||
assert!(list[0].win);
|
||||
assert_eq!(list[0].format, Format::Arena3x6);
|
||||
assert!(list[0].when.contains("2026"), "{}", list[0].when);
|
||||
assert!(match_list(&tracker, "someone-else").unwrap().is_empty());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user