Open « Statistiques » from the Challenge banner, not the top bar (#107)
A « Statistiques › » link under the counter opens it with the usual veil; « ‹ Défi » and the « Défi » tab bring the Challenge back, by mouse or keyboard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4ce9d02169
commit
665f129da0
11 files changed
+193
-93
No files matched your search
+28
-48
@@ -1,4 +1,4 @@
|
||||
//! The page and its two tabs: the shared state and the navigation. `display` renders the header
|
||||
//! The page and its two screens: the shared state and the navigation. `display` renders the header
|
||||
//! row and the alerts; `home`, `champ_select` and `statistics` render the content under them.
|
||||
|
||||
use crate::banner_art::BannerArt;
|
||||
@@ -19,7 +19,6 @@ use gpui_kit::base::async_util::Sender;
|
||||
use gpui_kit::component::input::InputState;
|
||||
use gpui_kit::component::select::{SelectItem, SelectState};
|
||||
use gpui_kit::component::{ActiveTheme as _, StyledExt as _};
|
||||
use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::*;
|
||||
use profiling::shown;
|
||||
use scrollbar::PageScrollbar;
|
||||
@@ -36,6 +35,7 @@ mod displayed;
|
||||
mod home;
|
||||
mod hover;
|
||||
mod lifecycle;
|
||||
mod links;
|
||||
mod playback;
|
||||
mod profiling;
|
||||
mod scrollbar;
|
||||
@@ -102,7 +102,8 @@ impl EventEmitter<ChampSelectTransition> for Page {}
|
||||
pub struct ChampionSortChosen(pub ChampionSort);
|
||||
impl EventEmitter<ChampionSortChosen> for Page {}
|
||||
|
||||
/// The two pages the navigation switches between.
|
||||
/// The two screens the page switches between: « Défi » is the only tab of the top bar, and
|
||||
/// « Statistiques » its detail page, opened from the banner.
|
||||
#[derive(Clone, Copy, PartialEq, Debug)]
|
||||
enum Tab {
|
||||
/// « Défi », the home: the Challenge of one Season.
|
||||
@@ -308,53 +309,32 @@ pub struct Page {
|
||||
}
|
||||
|
||||
impl Page {
|
||||
/// The two tabs as buttons: they take the keyboard focus, and Enter or Space activates them.
|
||||
/// « Défi » as a button: it takes the keyboard focus, and Enter or Space activates it. It
|
||||
/// stays lit on « Statistiques », the Challenge's detail page, and takes back to the
|
||||
/// Challenge from there.
|
||||
fn navigation(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let (ring, muted, active, active_foreground, hover, hover_foreground) = (
|
||||
theme.ring,
|
||||
theme.tab_foreground,
|
||||
theme.tab_active,
|
||||
theme.tab_active_foreground,
|
||||
theme.accent,
|
||||
theme.accent_foreground,
|
||||
);
|
||||
let tabs = [
|
||||
("tab-challenge", "Défi", Tab::Challenge),
|
||||
("tab-statistics", "Statistiques", Tab::Statistics),
|
||||
];
|
||||
div()
|
||||
.h_flex()
|
||||
.gap_1()
|
||||
.flex_shrink_0()
|
||||
.children(tabs.map(|(id, label, tab)| {
|
||||
let current = self.tab == tab;
|
||||
// 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)
|
||||
.px_3()
|
||||
.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 && !disabled, |button| {
|
||||
button.hover(|style| style.bg(hover).text_color(hover_foreground))
|
||||
})
|
||||
.when(disabled, |button| button.opacity(0.5))
|
||||
.accessibility_label(label)
|
||||
.debug_selector(|| id.into())
|
||||
.child(label)
|
||||
.on_click(cx.listener(move |this, _, window, cx| this.set_tab(tab, window, cx)))
|
||||
}))
|
||||
let (active, active_foreground) = (theme.tab_active, theme.tab_active_foreground);
|
||||
div().h_flex().gap_1().flex_shrink_0().child(
|
||||
BaseButton::new("tab-challenge")
|
||||
.px_3()
|
||||
.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(active_foreground))
|
||||
.text_color(active_foreground)
|
||||
.bg(active)
|
||||
.accessibility_label("Défi")
|
||||
.debug_selector(|| "tab-challenge".into())
|
||||
.child("Défi")
|
||||
.on_click(
|
||||
cx.listener(|this, _, window, cx| this.set_tab(Tab::Challenge, window, cx)),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn set_tab(&mut self, tab: Tab, window: &mut Window, cx: &mut Context<Self>) {
|
||||
|
||||
@@ -5,6 +5,7 @@ use gpui_kit::*;
|
||||
use super::{BannerContent, Line, NO_SEASON, Page};
|
||||
use crate::banner_art::BannerArt;
|
||||
use crate::motion::{COUNTER_ROLL, ease_out};
|
||||
use crate::page::Tab;
|
||||
use crate::ring::{self, Tick};
|
||||
use crate::theme::{banner_band, gold_ink, heading};
|
||||
use std::rc::Rc;
|
||||
@@ -112,6 +113,16 @@ impl Page {
|
||||
.child(name(line))
|
||||
}))
|
||||
.into_any_element()
|
||||
}))
|
||||
// The champ select takes the window: « Statistiques » waits for its end.
|
||||
.children((!self.in_champ_select()).then(|| {
|
||||
div().v_flex().mt(px(6.)).child(self.tab_link(
|
||||
"statistics-link",
|
||||
"Statistiques ›",
|
||||
Tab::Statistics,
|
||||
ink,
|
||||
cx,
|
||||
))
|
||||
}));
|
||||
div()
|
||||
.relative()
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
//! The page's text links: « Statistiques › » on the Challenge's banner and « ‹ Défi » on the
|
||||
//! statistics page. Real buttons, so the keyboard reaches them (Tab, then Enter or Space).
|
||||
|
||||
use super::Tab;
|
||||
use gpui_kit::base::Button as BaseButton;
|
||||
use gpui_kit::component::ActiveTheme as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
use super::Page;
|
||||
|
||||
impl Page {
|
||||
/// A link that opens `tab`, in `ink` over the surface it stands on. Always bordered, so the
|
||||
/// focus ring does not shift the label. Its hover style redraws the page, never a cached
|
||||
/// view (rule #1).
|
||||
pub(super) fn tab_link(
|
||||
&self,
|
||||
id: &'static str,
|
||||
label: &'static str,
|
||||
tab: Tab,
|
||||
ink: Hsla,
|
||||
cx: &mut Context<Self>,
|
||||
) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let (ring, hover, hover_foreground) = (theme.ring, theme.accent, theme.accent_foreground);
|
||||
BaseButton::new(id)
|
||||
.self_start()
|
||||
.px_2()
|
||||
.py_1()
|
||||
.rounded_md()
|
||||
.text_sm()
|
||||
.font_weight(FontWeight::SEMIBOLD)
|
||||
.border_1()
|
||||
.border_color(transparent_black())
|
||||
.focus_visible(|style| style.border_color(ring))
|
||||
.text_color(ink)
|
||||
.hover(|style| style.bg(hover).text_color(hover_foreground))
|
||||
.accessibility_label(label)
|
||||
.debug_selector(|| id.into())
|
||||
.child(label)
|
||||
.on_click(cx.listener(move |this, _, window, cx| this.set_tab(tab, window, cx)))
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
//! The « Statistiques » tab: the analysis of one Account, Season and Format.
|
||||
//! The « Statistiques » page, the Challenge's detail: the analysis of one Account, Season and
|
||||
//! Format.
|
||||
|
||||
mod data;
|
||||
|
||||
@@ -11,7 +12,7 @@ use gpui_kit::component::{ActiveTheme as _, StyledExt as _, Theme};
|
||||
use gpui_kit::prelude::FluentBuilder as _;
|
||||
use gpui_kit::*;
|
||||
|
||||
use super::{Page, shown};
|
||||
use super::{Page, Tab as Screen, shown};
|
||||
use crate::text::{decimal, official_note};
|
||||
use crate::theme::{heading, surface};
|
||||
|
||||
@@ -311,6 +312,7 @@ impl Page {
|
||||
let options = filters(self.in_season());
|
||||
let selected = options.iter().position(|(_, f)| *f == self.filter);
|
||||
let challenge = self.stats.as_ref().and_then(|s| s.challenge.as_ref());
|
||||
let muted = cx.theme().muted_foreground;
|
||||
let mut content = Vec::new();
|
||||
// The Season and Format only exist where they are analysed: with the title, under the
|
||||
// transition's veil, so the header does not change while the screen leaving is visible.
|
||||
@@ -321,9 +323,23 @@ impl Page {
|
||||
.items_center()
|
||||
.justify_between()
|
||||
.gap_3()
|
||||
.when(shown("statistics-title"), |row| {
|
||||
row.child(heading(cx).text_3xl().child("Statistiques"))
|
||||
})
|
||||
.child(
|
||||
// « ‹ Défi » at the top left, then the title.
|
||||
div()
|
||||
.h_flex()
|
||||
.items_center()
|
||||
.gap_3()
|
||||
.child(self.tab_link(
|
||||
"back-to-challenge",
|
||||
"‹ Défi",
|
||||
Screen::Challenge,
|
||||
muted,
|
||||
cx,
|
||||
))
|
||||
.when(shown("statistics-title"), |row| {
|
||||
row.child(heading(cx).text_3xl().child("Statistiques"))
|
||||
}),
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.h_flex()
|
||||
|
||||
@@ -161,12 +161,12 @@ fn hovering_the_grid_draws_the_ring_only_for_the_tick_that_lights_or_goes_out(
|
||||
assert_eq!(ring_renders(&page, cx), renders + 2);
|
||||
|
||||
// Off the grid, over a button whose hover draws the page: the tick goes out once.
|
||||
let at = center(cx, "tab-statistics");
|
||||
let at = center(cx, "statistics-link");
|
||||
hover(cx, at);
|
||||
assert_eq!(lit(cx), None);
|
||||
assert_eq!(ring_renders(&page, cx), renders + 3);
|
||||
hover(cx, point(px(5.), px(5.)));
|
||||
let at = center(cx, "tab-statistics");
|
||||
let at = center(cx, "statistics-link");
|
||||
hover(cx, at);
|
||||
assert_eq!(ring_renders(&page, cx), renders + 3);
|
||||
|
||||
|
||||
@@ -254,9 +254,9 @@ async fn the_champ_select_takes_the_home_and_gives_it_back_as_it_was(cx: &mut Te
|
||||
assert!(window.debug_bounds("home-tools").is_none());
|
||||
assert!(window.debug_bounds("card-103").is_none());
|
||||
|
||||
// « Statistiques » is out of reach during the champ select.
|
||||
let statistics = center(&mut window, "tab-statistics");
|
||||
window.simulate_click(statistics, Modifiers::none());
|
||||
// « Statistiques » is out of reach during the champ select: no link in the banner.
|
||||
assert!(window.debug_bounds("statistics-link").is_none());
|
||||
assert!(window.debug_bounds("tab-statistics").is_none());
|
||||
switch_tab(&page, &mut window, Tab::Statistics);
|
||||
assert_eq!(page.read_with(&window, |p, _| p.tab), Tab::Challenge);
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ fn hovering_outside_the_grid_does_not_render_the_cards(cx: &mut TestAppContext)
|
||||
|
||||
// A navigation button's hover style redraws the window.
|
||||
for _ in 0..2 {
|
||||
let button = center(cx, "tab-statistics");
|
||||
let button = center(cx, "statistics-link");
|
||||
cx.simulate_mouse_move(button, None, Modifiers::none());
|
||||
draw(cx);
|
||||
cx.simulate_mouse_move(point(px(5.), px(5.)), None, Modifiers::none());
|
||||
|
||||
@@ -8,35 +8,8 @@ use gpui_kit::{
|
||||
WindowVisibility,
|
||||
};
|
||||
|
||||
#[gpui::test]
|
||||
fn the_navigation_switches_tabs_with_the_mouse(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page(cx);
|
||||
let cx = &mut { cx };
|
||||
let tab = |cx: &mut VisualTestContext| page.read_with(cx, |page, _| page.tab);
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
assert_eq!(tab(cx), Tab::Challenge);
|
||||
|
||||
let statistics = center(cx, "tab-statistics");
|
||||
cx.simulate_click(statistics, Modifiers::none());
|
||||
assert_eq!(tab(cx), Tab::Statistics);
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
|
||||
let challenge = center(cx, "tab-challenge");
|
||||
cx.simulate_click(challenge, Modifiers::none());
|
||||
assert_eq!(tab(cx), Tab::Challenge);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_navigation_switches_tabs_with_the_keyboard(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page(cx);
|
||||
let cx = &mut { cx };
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
// Tab reaches « Défi » first, then « Statistiques ».
|
||||
cx.update(|window, cx| {
|
||||
window.focus_next(cx);
|
||||
window.focus_next(cx);
|
||||
});
|
||||
cx.update(|window, cx| window.draw(cx).clear(cx));
|
||||
/// Presses Enter on the element focused, as the keyboard does.
|
||||
fn press_enter(cx: &mut VisualTestContext) {
|
||||
let enter =
|
||||
cx.update(|_, cx| Keystroke::parse_with_os("enter", cx.platform_info().os).unwrap());
|
||||
cx.simulate_event(KeyDownEvent {
|
||||
@@ -45,7 +18,77 @@ fn the_navigation_switches_tabs_with_the_keyboard(cx: &mut TestAppContext) {
|
||||
prefer_character_input: false,
|
||||
});
|
||||
cx.simulate_event(KeyUpEvent { keystroke: enter });
|
||||
assert_eq!(page.read_with(cx, |page, _| page.tab), Tab::Statistics);
|
||||
}
|
||||
|
||||
/// Tab moves the focus `count` elements on, then Enter activates the one reached.
|
||||
fn tab_then_enter(cx: &mut VisualTestContext, count: usize) {
|
||||
cx.update(|window, cx| {
|
||||
for _ in 0..count {
|
||||
window.focus_next(cx);
|
||||
}
|
||||
});
|
||||
draw(cx);
|
||||
press_enter(cx);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_top_bar_has_no_statistics_tab(cx: &mut TestAppContext) {
|
||||
let (_page, cx) = open_page(cx);
|
||||
let cx = &mut { cx };
|
||||
draw(cx);
|
||||
assert!(cx.debug_bounds("tab-challenge").is_some());
|
||||
assert!(cx.debug_bounds("tab-statistics").is_none());
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_banner_link_opens_the_page_and_the_back_button_returns_with_the_mouse(
|
||||
cx: &mut TestAppContext,
|
||||
) {
|
||||
let (page, cx) = open_page(cx);
|
||||
let cx = &mut { cx };
|
||||
let tab = |cx: &mut VisualTestContext| page.read_with(cx, |page, _| page.tab);
|
||||
draw(cx);
|
||||
assert_eq!(tab(cx), Tab::Challenge);
|
||||
assert!(cx.debug_bounds("back-to-challenge").is_none());
|
||||
|
||||
let link = center(cx, "statistics-link");
|
||||
cx.simulate_click(link, Modifiers::none());
|
||||
assert_eq!(tab(cx), Tab::Statistics);
|
||||
// The same veil as any switch: the page is shown once it covers the screen.
|
||||
assert_eq!(shown_tab(&page, cx), Tab::Challenge);
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
draw(cx);
|
||||
assert!(cx.debug_bounds("statistics-link").is_none());
|
||||
|
||||
let back = center(cx, "back-to-challenge");
|
||||
cx.simulate_click(back, Modifiers::none());
|
||||
assert_eq!(tab(cx), Tab::Challenge);
|
||||
switch_tab(&page, cx, Tab::Challenge);
|
||||
draw(cx);
|
||||
|
||||
// « Défi » stays in the top bar on « Statistiques », and takes back too.
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
draw(cx);
|
||||
let challenge = center(cx, "tab-challenge");
|
||||
cx.simulate_click(challenge, Modifiers::none());
|
||||
assert_eq!(tab(cx), Tab::Challenge);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn the_banner_link_and_the_back_button_work_with_the_keyboard(cx: &mut TestAppContext) {
|
||||
let (page, cx) = open_page(cx);
|
||||
let cx = &mut { cx };
|
||||
let tab = |cx: &mut VisualTestContext| page.read_with(cx, |page, _| page.tab);
|
||||
draw(cx);
|
||||
// Tab reaches « Défi », then the account selector, then « Statistiques › » in the banner.
|
||||
tab_then_enter(cx, 3);
|
||||
assert_eq!(tab(cx), Tab::Statistics);
|
||||
switch_tab(&page, cx, Tab::Statistics);
|
||||
draw(cx);
|
||||
|
||||
// On the page, « Défi », the selector, then « ‹ Défi ».
|
||||
tab_then_enter(cx, 3);
|
||||
assert_eq!(tab(cx), Tab::Challenge);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
|
||||
Reference in new issue
Block a user