feat(purchases): wire navigation + view persistence (Slint)

Slice 11/13. NavEntry::PurchaseDetail(String) + full routing (scope_for/
apply_entry, history recording + update_nav_flags on purchase-album clicks and
the Purchases route), session-restore-safe purchases (id-gated purchase-album),
conditional-mount guard + A.3 reactive reload (back/forward between two purchase
albums re-fetches). Sidebar ShoppingBag row + HeaderBar tabs (full+compact),
gated on show-purchases && !offline, active for both purchases + purchase-album.
nav.rs round-trip history test. Type-check clean (exit-0 not reachable on this
box; SIGTERM at metadata = memory limit).

cc
This commit is contained in:
vicrodh committed 2026-06-24 17:12:58 -06:00
1 parent eab178c1e3
commit 965c898b10
5 files changed
+199 -6

No files matched your search

+45 -3
View File
@@ -442,6 +442,10 @@ async fn enter_shell(
}),
"mixtapes" => Some(nav::NavEntry::Mixtapes),
"collections" => Some(nav::NavEntry::Collections),
// Purchases restores at startup (id-free top-level surface).
// `purchase-album` is never persisted (id-gated, not in
// safe_view_key), so it never reaches here.
"purchases" => Some(nav::NavEntry::Purchases),
// "home" / unknown → keep the Home already loaded above.
_ => None,
};
@@ -962,6 +966,11 @@ fn safe_view_key(view: ContentView) -> Option<&'static str> {
ContentView::LocalLibrary => Some("local-library"),
ContentView::Mixtapes => Some("mixtapes"),
ContentView::Collections => Some("collections"),
// Purchases is session-restore-safe (id-free top-level surface — §8.6).
// The `purchase-album` detail view carries a context id that may be
// stale on restart, so it is NOT restorable (returns None below),
// matching how Album/Artist detail views are handled here.
ContentView::Purchases => Some("purchases"),
_ => None,
}
}
@@ -1740,6 +1749,7 @@ fn scope_for(entry: &nav::NavEntry) -> String {
nav::NavEntry::Award { .. } => "award".into(),
nav::NavEntry::AwardAlbums { .. } => "award-albums".into(),
nav::NavEntry::Purchases => "purchases".into(),
nav::NavEntry::PurchaseDetail(_) => "purchase-album".into(),
nav::NavEntry::ArtistReleases { .. } => "artist-releases".into(),
nav::NavEntry::Location { .. } => "location".into(),
}
@@ -1863,6 +1873,13 @@ fn apply_entry(
nav::NavEntry::Purchases => {
navigate_purchases(runtime.clone(), weak.clone(), handle, image_cache.clone());
}
nav::NavEntry::PurchaseDetail(id) => {
// Seed the bound id + switch the view; the detail view's
// `changed album-id` handler fires the fresh fetch (§A.3 reactive
// reload), so back/forward between two purchase albums never shows
// stale data. The conditional-mount guard requires the non-empty id.
navigate_purchase_detail(weak.clone(), &id);
}
nav::NavEntry::ArtistReleases {
id,
name,
@@ -5645,12 +5662,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
// Open a purchase album DETAIL view (from a Purchases grid/list card).
// Seeds the bound id + switches the view; the view's `changed album-id`
// handler fires the fetch (§A.3). Slice 11 layers nav-history + persistence.
// Records the back/forward history entry, seeds the bound id + switches the
// view; the view's `changed album-id` handler fires the fetch (§A.3
// reactive reload). Mirrors `on_open_album`'s record + navigate +
// update_nav_flags shape (§5.2 `handlePurchaseAlbumClick`).
{
let weak = window.as_weak();
window.on_open_purchase_album(move |album_id| {
navigate_purchase_detail(weak.clone(), album_id.as_str());
let id = album_id.to_string();
nav::record(nav::NavEntry::PurchaseDetail(id.clone()));
navigate_purchase_detail(weak.clone(), &id);
if let Some(w) = weak.upgrade() {
update_nav_flags(&w);
}
});
}
@@ -12425,6 +12449,24 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
return;
}
// Purchases — the opt-in My-Purchases surface. Direct nav item (no
// tab dropdown): record history + navigate (loads the active tab) +
// update_nav_flags, mirroring the My QBZ / Favorites per-route
// pattern. Active highlight for both `purchases`/`purchase-album`
// is computed view-side off NavState.view (§5.3).
if route == "purchases" {
nav::record(nav::NavEntry::Purchases);
if let Some(w) = weak.upgrade() {
update_nav_flags(&w);
}
navigate_purchases(
runtime.clone(),
weak.clone(),
&handle,
image_cache.clone(),
);
return;
}
// My QBZ — Mixtapes / Collections index grids (read-only slice).
// Record history + navigate (loads via myqbz::navigate), mirroring
// the Favorites / Local Library per-route pattern.
+33 -1
View File
@@ -130,8 +130,15 @@ pub enum NavEntry {
/// PurchasesView — the My-Purchases library surface (opt-in feature). The
/// in-view toolbar state (tab/search/filter/sort/group) is session-scoped
/// in the controller + persisted prefs, so the entry carries no payload.
/// (The `purchase-album` detail entry lands in Slice 11.)
Purchases,
/// PurchaseAlbumDetailView — the per-album purchase detail / download
/// surface, reached by clicking a purchase grid/list card. The string is
/// the purchase album id. Mirrors `Album` — the in-detail toolbar/format/
/// download state is session-scoped (the download store survives navigation
/// on the controller), so the entry carries only the id. Conditional-mount:
/// the view only mounts with a non-empty selected id (ADR-010); §A.3
/// reactive-reload re-fetches whenever this id changes.
PurchaseDetail(String),
/// ArtistReleasesView — the dedicated discography listing for one
/// release bucket, reached via "See discography" on the artist page.
ArtistReleases {
@@ -378,6 +385,31 @@ mod tests {
assert_eq!(nav_of(go_back()), Some(NavEntry::Home));
}
#[test]
fn purchases_and_detail_round_trip_history() {
reset();
// Purchases list → detail album A → detail album B.
record(NavEntry::Purchases);
record(NavEntry::PurchaseDetail("A".into()));
record(NavEntry::PurchaseDetail("B".into()));
// Back walks B → A → list → Home; forward returns to A then B.
assert_eq!(
nav_of(go_back()),
Some(NavEntry::PurchaseDetail("A".into()))
);
assert_eq!(nav_of(go_back()), Some(NavEntry::Purchases));
assert_eq!(nav_of(go_back()), Some(NavEntry::Home));
assert_eq!(nav_of(go_forward()), Some(NavEntry::Purchases));
assert_eq!(
nav_of(go_forward()),
Some(NavEntry::PurchaseDetail("A".into()))
);
assert_eq!(
nav_of(go_forward()),
Some(NavEntry::PurchaseDetail("B".into()))
);
}
#[test]
fn record_dedupes_current_entry() {
reset();
+3
View File
@@ -187,6 +187,9 @@ export component AppShell inherits Rectangle {
recovery-login => {
root.recovery-login();
}
navigate(route) => {
root.header-menu-navigate(route);
}
}
HorizontalLayout {
+58 -1
View File
@@ -14,7 +14,7 @@ import { Spacing } from "../foundation/spacing.slint";
import { Typography } from "../foundation/typography.slint";
import { Layout } from "../foundation/layout.slint";
import { Radius } from "../foundation/radius.slint";
import { SessionState, NavState, ContentView, ShellState, HeaderMenuState, NavMenuEntry, SearchActions, SearchState, SidebarPlaylistsPopupState, OfflineState, SettingsState, OfflineModeActions } from "../state.slint";
import { SessionState, NavState, ContentView, ShellState, HeaderMenuState, NavMenuEntry, SearchActions, SearchState, SidebarPlaylistsPopupState, OfflineState, SettingsState, OfflineModeActions, AppearanceState } from "../state.slint";
import { QbzIcon } from "../primitives/QbzIcon.slint";
import { SecondaryButton } from "../primitives/SecondaryButton.slint";
import { QbzToggle } from "../primitives/QbzToggle.slint";
@@ -249,6 +249,33 @@ component CompactNavBtn inherits Rectangle {
}
}
// Compact DIRECT nav button (icon-only, no dropdown) — used by Purchases while
// the sidebar is fully closed. Active highlight reflects the current view.
component CompactDirectBtn inherits Rectangle {
in property <image> icon;
in property <bool> active: false;
callback clicked();
width: 30px;
height: 30px;
border-radius: Radius.sm;
background: root.active ? Theme.surface-elevated
: cd-ta.has-hover ? Theme.surface-hover : transparent;
QbzIcon {
source: root.icon;
width: 16px;
height: 16px;
x: Math.round((parent.width - self.width) / 2 / 1px) * 1px;
y: Math.round((parent.height - self.height) / 2 / 1px) * 1px;
tint: root.active ? Theme.text-primary : Theme.text-secondary;
}
cd-ta := TouchArea {
mouse-cursor: pointer;
clicked => { root.clicked(); }
}
}
// Like CompactNavBtn, but instead of a section dropdown it opens the playlists
// flyout (SidebarPlaylistsPopup). Shown in the closed-sidebar header cluster so
// playlists stay reachable with the sidebar fully collapsed. Header buttons are
@@ -516,6 +543,9 @@ export component HeaderBar inherits Rectangle {
// Forwarded up to AppShell — the badge flyout's "Sign in" (saved-token
// re-login during an unauthenticated offline session).
callback recovery-login();
// Direct route navigation (Purchases header tab) — funnels into the same
// `header-menu-navigate` route handler the dropdown menus use.
callback navigate(string /* route */);
height: Layout.header-height;
background: Theme.surface-card;
@@ -796,6 +826,21 @@ export component HeaderBar inherits Rectangle {
];
}
}
// Purchases — opt-in (default OFF). DIRECT tab (no dropdown), active
// for both the list + per-album detail views. HIDDEN while offline.
if AppearanceState.show-purchases && !OfflineState.offline: VerticalLayout {
alignment: center;
NavTab {
icon: @image-url("../assets/icons/shopping-bag.svg");
label: @tr("Purchases");
show-icon: root.show-tab-icons;
active: NavState.view == ContentView.purchases
|| NavState.view == ContentView.purchase-album;
clicked => {
root.navigate("purchases");
}
}
}
}
// Compact section nav — only while the sidebar is fully closed
// (Cerrado), so Discover / Library / Local Library / My QBZ stay
@@ -862,6 +907,18 @@ export component HeaderBar inherits Rectangle {
];
}
}
// Purchases — opt-in (default OFF). DIRECT button. HIDDEN offline.
if AppearanceState.show-purchases && !OfflineState.offline: VerticalLayout {
alignment: center;
CompactDirectBtn {
icon: @image-url("../assets/icons/shopping-bag.svg");
active: NavState.view == ContentView.purchases
|| NavState.view == ContentView.purchase-album;
clicked => {
root.navigate("purchases");
}
}
}
// Thin separator, then the playlists flyout button (no sidebar list
// to reach playlists from while fully closed).
Rectangle {
+60 -1
View File
@@ -16,7 +16,7 @@ import { QbzIcon } from "../primitives/QbzIcon.slint";
import { SidebarPlaylistCollage } from "../primitives/SidebarPlaylistCollage.slint";
import { ContextMenu } from "../primitives/ContextMenu.slint";
import { ContextMenuItem } from "../primitives/ContextMenuItem.slint";
import { ShellState, SidebarState, SidebarActions, SidebarEntry, DragState, HeaderMenuState, NavMenuEntry, SidebarFolderPopupState, SidebarTooltipState, MyQbzBrandingState, OfflineState } from "../state.slint";
import { ShellState, SidebarState, SidebarActions, SidebarEntry, DragState, HeaderMenuState, NavMenuEntry, SidebarFolderPopupState, SidebarTooltipState, MyQbzBrandingState, OfflineState, NavState, ContentView, AppearanceState } from "../state.slint";
import { ScrollView, LineEdit } from "std-widgets.slint";
// A single context-menu item row.
@@ -628,6 +628,52 @@ component SidebarNavRow inherits Rectangle {
}
}
// A DIRECT sidebar nav row (no dropdown flyout) — used by Purchases, which is
// a single destination (§5.3 NavigationItem), not a section with tabs. Clicking
// navigates straight to the route; the active highlight reflects the current
// view (paints surface-hover + primary text/icon, like the section rows do
// while their flyout is open).
component SidebarDirectRow inherits Rectangle {
in property <image> icon;
in property <string> label;
in property <bool> active: false;
callback clicked();
height: 34px;
border-radius: 6px;
background: (nav-ta.has-hover || root.active) ? Theme.surface-hover : transparent;
HorizontalLayout {
padding-left: ShellState.sidebar-mini ? 0px : 8px;
padding-right: ShellState.sidebar-mini ? 0px : 8px;
spacing: 10px;
alignment: ShellState.sidebar-mini ? center : start;
VerticalLayout {
alignment: center;
QbzIcon {
source: root.icon;
width: 16px;
height: 16px;
tint: (nav-ta.has-hover || root.active) ? Theme.text-primary : Theme.text-secondary;
}
}
if !ShellState.sidebar-mini: Text {
text: root.label;
color: (nav-ta.has-hover || root.active) ? Theme.text-primary : Theme.text-secondary;
font-size: 13px;
font-weight: 500;
vertical-alignment: center;
horizontal-stretch: 1;
}
}
nav-ta := TouchArea {
mouse-cursor: pointer;
clicked => {
root.clicked();
}
}
}
export component Sidebar inherits Rectangle {
// Fired when a sidebar section-nav row is clicked — wired in AppShell to
// the same route handler the header dropdowns use.
@@ -707,6 +753,19 @@ export component Sidebar inherits Rectangle {
{ label: @tr("Collections"), icon: @image-url("../assets/icons/collection.svg"), has-glyph: true, route: "myqbz-collections" },
];
}
// Purchases — opt-in (Settings > Appearance, default OFF). A DIRECT
// destination (no tab dropdown). HIDDEN entirely while offline (the
// surface needs the Qobuz session). Active for both the list view
// and the per-album detail view (§5.3 / §8.6 gating).
if AppearanceState.show-purchases && !OfflineState.offline: SidebarDirectRow {
icon: @image-url("../assets/icons/shopping-bag.svg");
label: @tr("Purchases");
active: NavState.view == ContentView.purchases
|| NavState.view == ContentView.purchase-album;
clicked => {
root.navigate("purchases");
}
}
}
if ShellState.nav-in-sidebar: Rectangle {
height: 1px;