feat(purchases): add PurchasesView list UI + nav mount (Slint)

Slice 8/13. New ui/purchases/PurchasesView.slint (list surface: Albums/Tracks
tabs+counts, debounced search, group/sort/filter, grid/list toggle, format-picker
popup, quality radios, unavailable overlay, bare track-row quality A.6) reusing
SegmentedTabBar/ExpandableSearch/QbzSelect/AlbumCollectionView/TrackRow. Wires
PurchasesState/PurchasesActions globals (state.slint + app.slint export bridge),
AppShell mount on ContentView.purchases, NavEntry::Purchases, artwork target,
controller apply/derive/actions in purchases.rs, shopping-bag/download icons.
28 unit tests green.

1:1 fix: download-track fetch error shows downloadFailed toast (not noFormats);
get_album_formats returns Result to distinguish fetch failure from empty list.

cc
This commit is contained in:
vicrodh committed 2026-06-24 09:53:39 -06:00
1 parent 44aa4e1462
commit 06dd52e5d4
10 files changed
+3486 -7

No files matched your search

+27
View File
@@ -202,6 +202,13 @@ pub enum ArtworkTarget {
/// A row thumbnail in the immersive Suggestions recommended-tracks list
/// (`SuggestionsState.tracks[idx]`).
SuggestionTrackCover { idx: usize },
/// A cover of `PurchasesState.albums-full[index]` (the stable artwork-target
/// full set). The apply arm writes here, then dual-sets by id into the
/// rendered flat + grouped models (which a filter/sort/group re-derives).
PurchaseAlbum { index: usize },
/// A thumbnail of `PurchasesState.tracks-full[index]` (artwork-target full
/// set). Dual-set by id into the rendered flat + grouped track models.
PurchaseTrack { index: usize },
}
impl ArtworkTarget {
@@ -1090,6 +1097,26 @@ fn apply_artwork(
model.set_row_data(index, item);
}
}
ArtworkTarget::PurchaseAlbum { index } => {
let model = window.global::<crate::PurchasesState>().get_albums_full();
if let Some(mut item) = model.row_data(index) {
item.artwork = image.clone();
let id = item.id.to_string();
model.set_row_data(index, item);
// Also reach the rendered flat + grouped models (re-derived by a
// filter/sort/group, so they don't share `albums-full`).
crate::purchases::set_album_artwork(window, &id, image);
}
}
ArtworkTarget::PurchaseTrack { index } => {
let model = window.global::<crate::PurchasesState>().get_tracks_full();
if let Some(mut item) = model.row_data(index) {
item.artwork = image.clone();
let id = item.id.to_string();
model.set_row_data(index, item);
crate::purchases::set_track_artwork(window, &id, image);
}
}
ArtworkTarget::LocalAlbumCard { index, gen } => {
// Drop the cover if a reload superseded the set it belongs to.
if !crate::local_library::albums_gen_current(gen) {
+528
View File
@@ -1739,6 +1739,7 @@ fn scope_for(entry: &nav::NavEntry) -> String {
nav::NavEntry::LabelReleases { .. } => "label-releases".into(),
nav::NavEntry::Award { .. } => "award".into(),
nav::NavEntry::AwardAlbums { .. } => "award-albums".into(),
nav::NavEntry::Purchases => "purchases".into(),
nav::NavEntry::ArtistReleases { .. } => "artist-releases".into(),
nav::NavEntry::Location { .. } => "location".into(),
}
@@ -1859,6 +1860,9 @@ fn apply_entry(
name,
);
}
nav::NavEntry::Purchases => {
navigate_purchases(runtime.clone(), weak.clone(), handle, image_cache.clone());
}
nav::NavEntry::ArtistReleases {
id,
name,
@@ -2236,6 +2240,133 @@ fn navigate_award_albums(
});
}
/// Open the My-Purchases surface and lazy-load the active tab. Mirrors
/// `navigate_favorites`: the view mounts immediately (spinner), then the active
/// tab's data + the metadata (dlIds + per-type totals) load and project onto
/// `PurchasesState`. The toolbar/filter state survives navigation in the
/// controller cache, so re-entering shows the same view without a refetch.
fn navigate_purchases(
runtime: Arc<AppRuntime<SlintAdapter>>,
weak: slint::Weak<AppWindow>,
handle: &tokio::runtime::Handle,
image_cache: artwork::ImageCache,
) {
let _ = weak.upgrade_in_event_loop(|w| {
w.global::<NavState>().set_view(ContentView::Purchases);
});
// Lazy-load the active tab (skip if already cached — the switch-back quirk).
let active = purchases_active_tab(&weak);
load_purchases_tab(runtime, weak, handle.clone(), image_cache, active, false, false);
}
/// Read the active purchases tab off `PurchasesState` (default Albums).
fn purchases_active_tab(weak: &slint::Weak<AppWindow>) -> purchases::PurchaseTab {
weak.upgrade()
.map(|w| {
if w.global::<PurchasesState>().get_active_tab() == "tracks" {
purchases::PurchaseTab::Tracks
} else {
purchases::PurchaseTab::Albums
}
})
.unwrap_or(purchases::PurchaseTab::Albums)
}
/// Map a `load_purchases_by_tab` error to its display string: the i18n key
/// `purchases.loadFailed` resolves to its (English) text — the list view
/// i18n-maps `purchases.`-prefixed errors — while a raw error passes through.
fn map_purchases_error_display(err: &str) -> String {
if err == "purchases.loadFailed" {
qbz_i18n::t("Couldn't load purchases. Check your connection.")
} else {
err.to_string()
}
}
/// Load (or refresh) one purchases tab: set loading, fetch metadata + the tab
/// list, then apply or surface the error. `force` skips the cache guard;
/// `search_overwrote` marks BOTH tabs loaded (the search path). On success
/// spawns artwork for the tab's covers.
fn load_purchases_tab(
runtime: Arc<AppRuntime<SlintAdapter>>,
weak: slint::Weak<AppWindow>,
handle: tokio::runtime::Handle,
image_cache: artwork::ImageCache,
tab: purchases::PurchaseTab,
force: bool,
search_overwrote: bool,
) {
// Cache guard (Svelte `loadPurchasesByTab` early-return): skip the refetch
// when the tab is already loaded and we're not forcing.
if !force && purchases::tab_cached(tab) {
let _ = weak.upgrade_in_event_loop(move |w| {
// Still ensure the rendered models reflect the current toolbar state.
purchases::set_loading_done(&w);
purchases::derive_purchases(&w);
});
return;
}
handle.spawn(async move {
let _ = weak.upgrade_in_event_loop(|w| {
purchases::set_loading(&w);
});
let metadata = purchases::load_purchases_metadata(&runtime).await;
match purchases::load_purchases_by_tab(&runtime, tab, &metadata).await {
Ok(payload) => {
let _ = weak.upgrade_in_event_loop(move |w| {
purchases::apply_purchases_tab(&w, tab, payload, &metadata, search_overwrote);
});
let jobs = purchases::artwork_jobs_for_tab(tab);
artwork::spawn_loads(jobs, weak.clone(), image_cache.clone());
}
Err(e) => {
let display = map_purchases_error_display(&e);
let _ = weak.upgrade_in_event_loop(move |w| {
purchases::set_load_error(&w, &display);
});
}
}
});
}
/// Execute a tracks-tab per-track download for a chosen format (§2.1.13
/// `executeTrackDownload`): folder-pick (cancel = abort), derive the qualityDir
/// from the format label, then fire the single-track download. The live row
/// status refreshes via the controller's `start_track_download` refresh nudge.
fn execute_track_download(
runtime: Arc<AppRuntime<SlintAdapter>>,
weak: slint::Weak<AppWindow>,
handle: tokio::runtime::Handle,
track_id: u64,
fmt: qbz_models::PurchaseFormatOption,
) {
let Some(track) = purchases::find_track(track_id) else {
return;
};
let album_id = match track.album.as_ref() {
Some(a) if !a.id.is_empty() => a.id.clone(),
_ => return,
};
let handle2 = handle.clone();
handle.spawn(async move {
// Folder picker (cancel → abort, Svelte `if (!dest) return`).
let Some(dest) = purchases::pick_download_folder().await else {
return;
};
let quality_dir = purchases::quality_dir(&fmt.label);
purchases::start_track_download(
runtime,
weak,
handle2,
album_id,
track_id,
fmt.id,
dest,
quality_dir,
);
});
}
/// Open Library > Favorites on `tab` and lazy-load that tab's data.
/// Switching the active tab also routes here so each tab fetches on
/// first view (Tauri's loadTabIfNeeded).
@@ -6778,6 +6909,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
window.on_logout(move || {
// Drop any Discord "now listening" activity on logout.
discord_rpc::clear(&handle);
// Clear the per-user purchases cache + download-status store so the
// next account never sees the previous user's purchased items or
// in-flight download statuses (cross-account data leak).
purchases::reset_ui_cache();
let runtime = runtime.clone();
let weak = weak.clone();
handle.spawn(async move {
@@ -10688,6 +10823,399 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
});
}
// PurchasesView actions (Slice 8 — list surface).
{
// select-tab — switch + lazy-load the new tab (cached after first load;
// switching back does NOT refetch). Sets active-tab THEN loads.
let runtime = app_runtime.clone();
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
let image_cache = image_cache.clone();
window.global::<PurchasesActions>().on_select_tab(move |tab| {
let Some(w) = weak.upgrade() else { return };
w.global::<PurchasesState>().set_active_tab(tab.clone());
// Close any open menu on a tab switch (Svelte closeFormatPicker too).
w.global::<PurchasesState>().set_open_menu(slint::SharedString::new());
let pt = if tab == "tracks" {
purchases::PurchaseTab::Tracks
} else {
purchases::PurchaseTab::Albums
};
// Tab-switch effect: only loads if NOT search-scoped + not cached.
if w.global::<PurchasesState>().get_search_query().trim().is_empty() {
load_purchases_tab(
runtime.clone(),
weak.clone(),
handle.clone(),
image_cache.clone(),
pt,
false,
false,
);
} else {
// Search active: just re-derive the new tab's view from the
// already-loaded search arrays (no refetch).
purchases::derive_purchases(&w);
}
});
}
{
// search(query) — 300ms debounce in the controller. Empty query → force
// reload the active tab; else fetch ALL purchases + filter, set both
// arrays + both loaded.
let runtime = app_runtime.clone();
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
let image_cache = image_cache.clone();
window.global::<PurchasesActions>().on_search(move |query| {
let query = query.to_string();
let seq = purchases::next_search_seq();
let runtime = runtime.clone();
let weak = weak.clone();
let handle2 = handle.clone();
let image_cache = image_cache.clone();
handle.spawn(async move {
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
// Debounce: drop a stale fire (a newer keystroke superseded it).
if !purchases::search_seq_current(seq) {
return;
}
let trimmed = query.trim().to_string();
if trimmed.is_empty() {
// Empty query → force reload the active tab (clearSearch-ish).
purchases::set_search_active(false);
let active = purchases_active_tab(&weak);
load_purchases_tab(
runtime, weak, handle2, image_cache, active, true, false,
);
return;
}
let _ = weak.upgrade_in_event_loop(|w| {
purchases::set_loading(&w);
});
let metadata = purchases::load_purchases_metadata(&runtime).await;
match purchases::search_purchases(&runtime, &trimmed).await {
Ok((albums, tracks)) => {
let _ = weak.upgrade_in_event_loop(move |w| {
purchases::apply_purchases_search(&w, albums, tracks, &metadata);
});
let jobs = purchases::artwork_jobs_for_both();
artwork::spawn_loads(jobs, weak.clone(), image_cache.clone());
}
Err(e) => {
let display = map_purchases_error_display(&e);
let _ = weak.upgrade_in_event_loop(move |w| {
purchases::set_load_error(&w, &display);
});
}
}
});
});
}
{
// clear-search — reset query + force reload only the active tab (the
// stale-other-tab quirk is preserved by NOT invalidating it).
let runtime = app_runtime.clone();
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
let image_cache = image_cache.clone();
window.global::<PurchasesActions>().on_clear_search(move || {
let Some(w) = weak.upgrade() else { return };
w.global::<PurchasesState>().set_search_query(slint::SharedString::new());
purchases::set_search_active(false);
let active = purchases_active_tab(&weak);
load_purchases_tab(
runtime.clone(),
weak.clone(),
handle.clone(),
image_cache.clone(),
active,
true,
false,
);
});
}
{
// Albums toolbar — group / view-mode / sort. Each writes state + derives.
let weak = window.as_weak();
window.global::<PurchasesActions>().on_set_album_group(move |mode| {
let Some(w) = weak.upgrade() else { return };
let s = w.global::<PurchasesState>();
if mode == "off" {
s.set_album_grouping_enabled(false);
} else {
s.set_album_group_mode(mode.clone());
s.set_album_grouping_enabled(true);
}
s.set_open_menu(slint::SharedString::new());
purchases::derive_purchases(&w);
});
}
{
let weak = window.as_weak();
window.global::<PurchasesActions>().on_set_album_view_mode(move |mode| {
let Some(w) = weak.upgrade() else { return };
w.global::<PurchasesState>().set_album_view_mode(mode);
purchases::derive_purchases(&w);
});
}
{
let weak = window.as_weak();
window.global::<PurchasesActions>().on_select_album_sort(move |value| {
let Some(w) = weak.upgrade() else { return };
let s = w.global::<PurchasesState>();
let (by, dir) = purchases::next_album_sort(
&s.get_album_sort_by(),
&s.get_album_sort_direction(),
&value,
);
s.set_album_sort_by(by.into());
s.set_album_sort_direction(dir.into());
s.set_open_menu(slint::SharedString::new());
purchases::derive_purchases(&w);
});
}
{
// Tracks toolbar — group dropdown.
let weak = window.as_weak();
window.global::<PurchasesActions>().on_set_track_group(move |mode| {
let Some(w) = weak.upgrade() else { return };
let s = w.global::<PurchasesState>();
if mode == "off" {
s.set_track_grouping_enabled(false);
} else {
s.set_track_group_mode(mode.clone());
s.set_track_grouping_enabled(true);
}
s.set_open_menu(slint::SharedString::new());
purchases::derive_purchases(&w);
});
}
{
// Filter panel setters (each persists in Slice 12; here: state + derive).
let weak = window.as_weak();
window
.global::<PurchasesActions>()
.on_set_filter_hide_unavailable(move |v| {
let Some(w) = weak.upgrade() else { return };
w.global::<PurchasesState>().set_filter_hide_unavailable(v);
purchases::derive_purchases(&w);
});
}
{
let weak = window.as_weak();
window.global::<PurchasesActions>().on_set_filter_quality(move |q| {
let Some(w) = weak.upgrade() else { return };
w.global::<PurchasesState>().set_filter_quality(q);
purchases::derive_purchases(&w);
});
}
{
let weak = window.as_weak();
window
.global::<PurchasesActions>()
.on_set_filter_hide_downloaded(move |v| {
let Some(w) = weak.upgrade() else { return };
w.global::<PurchasesState>().set_filter_hide_downloaded(v);
purchases::derive_purchases(&w);
});
}
{
let weak = window.as_weak();
window.global::<PurchasesActions>().on_clear_all_filters(move || {
let Some(w) = weak.upgrade() else { return };
let s = w.global::<PurchasesState>();
s.set_filter_hide_unavailable(false);
s.set_filter_quality("all".into());
s.set_filter_hide_downloaded(false);
purchases::derive_purchases(&w);
});
}
{
// Mutually-exclusive open menu ("" closes). No derive — UI-only.
let weak = window.as_weak();
window.global::<PurchasesActions>().on_set_open_menu(move |menu| {
let Some(w) = weak.upgrade() else { return };
w.global::<PurchasesState>().set_open_menu(menu);
// Opening any toolbar dropdown closes a format picker (Svelte).
w.global::<PurchasesState>().set_picker_track_id(slint::SharedString::new());
});
}
{
// Region notice dismiss — persisted in Slice 12; here: hide it.
let weak = window.as_weak();
window.global::<PurchasesActions>().on_dismiss_region_notice(move || {
let Some(w) = weak.upgrade() else { return };
w.global::<PurchasesState>().set_show_region_notice(false);
});
}
{
// open-album / open-artist (navigation lands fully in Slice 11; here we
// route artist clicks; album-detail clicks emit the view's open-album
// callback wired in AppShell, so this is a no-op placeholder kept for
// the Actions surface completeness).
let weak = window.as_weak();
window.global::<PurchasesActions>().on_open_artist(move |id| {
let Some(w) = weak.upgrade() else { return };
// Reuse the global open-artist path.
w.invoke_open_artist(id);
});
}
{
// play-track — single-track play with NO queue mutation (Slice 10
// finalizes the routing; here it goes through the standard media-action
// path emitted by the view).
let weak = window.as_weak();
window.global::<PurchasesActions>().on_play_track(move |id| {
let Some(w) = weak.upgrade() else { return };
w.invoke_media_action("track".into(), id, "play".into());
});
}
{
// download-track(track_id, ax, ay) — the tracks-tab per-track flow:
// resolve formats; 0 → toast; 1 → download directly; >1 → open picker.
let runtime = app_runtime.clone();
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
window
.global::<PurchasesActions>()
.on_download_track(move |track_id_s, ax, ay| {
let Some(w0) = weak.upgrade() else { return };
let Ok(track_id) = track_id_s.parse::<u64>() else { return };
let Some(track) = purchases::find_track(track_id) else { return };
// No album id → noAlbum toast (Svelte §2.1.13).
let album_id = track.album.as_ref().map(|a| a.id.clone()).unwrap_or_default();
if album_id.is_empty() {
crate::toast::error(&w0, qbz_i18n::t("This track has no album to download"));
return;
}
let runtime = runtime.clone();
let weak = weak.clone();
let handle2 = handle.clone();
handle.spawn(async move {
// 1:1 Svelte §2.1.13: a fetch FAILURE (Err) → `downloadFailed`;
// a successful-but-EMPTY format list (Ok(empty)) → `noFormats`.
let formats = match purchases::get_album_formats(&runtime, &album_id).await {
Ok(formats) => formats,
Err(_) => {
let _ = weak.upgrade_in_event_loop(|w| {
crate::toast::error(&w, qbz_i18n::t("Failed to start download. Please try again."));
});
return;
}
};
if formats.is_empty() {
let _ = weak.upgrade_in_event_loop(|w| {
crate::toast::error(&w, qbz_i18n::t("No downloadable formats available"));
});
return;
}
if formats.len() == 1 {
// 1 format → no picker; download directly.
let fmt = formats[0].clone();
execute_track_download(runtime, weak, handle2, track_id, fmt);
return;
}
// >1 → open the anchored picker. Cache the resolved formats
// keyed by track id so `pick-format` resolves the chosen
// option's label without a second `get_album` round-trip
// (the Svelte original keeps the formats in component state).
let items = purchases::format_picker_items(&formats);
purchases::cache_picker_formats(track_id, formats);
let _ = weak.upgrade_in_event_loop(move |w| {
let s = w.global::<PurchasesState>();
s.set_picker_formats(slint::ModelRc::new(slint::VecModel::from(items)));
s.set_picker_track_id(track_id.to_string().into());
s.set_picker_anchor_x(ax);
s.set_picker_anchor_y(ay);
// Opening the picker closes any toolbar menu.
s.set_open_menu(slint::SharedString::new());
});
});
});
}
{
// pick-format(track_id, format_id) — the user chose a format in the
// picker: close it, then folder-pick + download.
let runtime = app_runtime.clone();
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
window
.global::<PurchasesActions>()
.on_pick_format(move |track_id_s, format_id| {
let Some(w0) = weak.upgrade() else { return };
w0.global::<PurchasesState>().set_picker_track_id(slint::SharedString::new());
let Ok(track_id) = track_id_s.parse::<u64>() else { return };
let fid = format_id as u32;
// Resolve the chosen format option (for its label → qualityDir)
// from the cache `download-track` seeded when it opened the
// picker — no second `get_album` round-trip. The `_` arm is a
// defensive fallback if the cache was never seeded.
let cached = purchases::take_picker_formats(track_id)
.and_then(|formats| formats.into_iter().find(|f| f.id == fid));
let runtime = runtime.clone();
let weak = weak.clone();
let handle2 = handle.clone();
if let Some(fmt) = cached {
execute_track_download(runtime, weak, handle2, track_id, fmt);
return;
}
// Fallback: re-fetch (cache miss). Needs the album id.
let Some(track) = purchases::find_track(track_id) else { return };
let album_id = track.album.as_ref().map(|a| a.id.clone()).unwrap_or_default();
if album_id.is_empty() {
return;
}
handle.spawn(async move {
// Cache-miss re-fetch: a fetch failure simply aborts the
// download here (the picker was already shown; there is no
// Svelte toast on this fallback path — `executeTrackDownload`
// just returns when the format can't be resolved).
let Ok(formats) = purchases::get_album_formats(&runtime, &album_id).await else {
return;
};
let Some(fmt) = formats.into_iter().find(|f| f.id == fid) else {
return;
};
execute_track_download(runtime, weak, handle2, track_id, fmt);
});
});
}
{
// close-format-picker.
let weak = window.as_weak();
window.global::<PurchasesActions>().on_close_format_picker(move || {
let Some(w) = weak.upgrade() else { return };
let s = w.global::<PurchasesState>();
if let Ok(track_id) = s.get_picker_track_id().parse::<u64>() {
purchases::clear_picker_formats(track_id);
}
s.set_picker_track_id(slint::SharedString::new());
});
}
{
// retry — re-fetch the active tab (force). INTENTIONALLY UNWIRED in the
// UI for 1:1 parity: the Svelte error state renders icon + text with no
// retry button (PurchasesView.svelte:851-855), so the EmptyBlock has no
// trigger that fires this. Kept as a seam for a future retry affordance.
let runtime = app_runtime.clone();
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
let image_cache = image_cache.clone();
window.global::<PurchasesActions>().on_retry(move || {
let active = purchases_active_tab(&weak);
load_purchases_tab(
runtime.clone(),
weak.clone(),
handle.clone(),
image_cache.clone(),
active,
true,
false,
);
});
}
// Immersive Suggestions panel actions (Checkpoint D — split-panel == 2).
{
// load(track-id) — entry + now-playing-change refresh. Reads the
+5
View File
@@ -127,6 +127,11 @@ pub enum NavEntry {
id: String,
name: String,
},
/// 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,
/// ArtistReleasesView — the dedicated discography listing for one
/// release bucket, reached via "See discography" on the artist page.
ArtistReleases {
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -26,7 +26,7 @@ export { Theme, ThemeColors } from "foundation/semantic-colors.slint";
export { ThemeState } from "foundation/theme-state.slint";
// Re-export the state globals so the Rust layer can populate them.
export { HomeState, HomeActions, DiscoverState, DiscoverActions, SectionDescriptor, ConfigRow, DiscoverBrowseState, DiscoverBrowseActions, ForYouState, MixState, GenreFilterState, GenreFilterActions, AlbumState, ArtistState, NavState, ShellState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, LyricsState, LyricsLineItem, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions, LabelState, LabelActions, AwardState, AwardActions, AwardEntry, ArtistReleasesState, ArtistReleasesActions, LocationViewState, LocationViewActions, FavoritesState, FavoritesActions, PlaylistPickerState, PlaylistPickerActions, DuplicateConfirmState, DuplicateConfirmActions, PlaylistState, PlaylistActions, SidebarState, SidebarActions, SidebarFolderPopupState, CreatePlaylistState, CreatePlaylistActions, EditPlaylistState, EditPlaylistActions, CreateFolderState, CreateFolderActions, MyQbzCreateState, MyQbzCreateActions, DragState, DragActions, PlaylistManagerState, PlaylistManagerActions, OfflineManagerState, OfflineManagerActions, BlacklistState, BlacklistActions, BlacklistedArtistItem, MyQbzState, MyQbzActions, MixtapeCardItem, MyQbzAddState, MyQbzAddActions, MyQbzAddRow, MyQbzDetailState, MyQbzDetailActions, MixtapeDetailItem, MyQbzEditState, MyQbzEditActions, MyQbzMixState, MyQbzMixActions, DiscoBuilderState, DiscoBuilderActions, DiscoGroup, DiscoCandidate, LocalLibraryState, LocalLibraryActions, LibraryFoldersState, LibFolderEditState, LibraryManageActions, LibraryScanState, LibAlbumFilterState, LocalAlbumState, LocalAlbumActions, TagEditorState, TagEditorActions, FolderEditState, FolderEditActions, ToastState, TextUtil, QconnectDevState, QconnectDevice, CastState, CastDevice, CastActions, AppearanceState, MyQbzBrandingState, EphemeralPlayChoiceState, EphemeralPlayChoiceActions, PlexSettingsState, PlexAuthActions, PlexSectionItem, ScrobbleState, ScrobbleActions, DiscordState, OfflineState, OfflineModeActions, OfflineFavoritesState, OfflineFavoritesActions, ImportLogEntry, PlaylistImportState, PlaylistImportActions, DacWizardState, DacWizardActions, DacCandidateRow, RemediationRow, DacConfigRow, InfoCreditRow, InfoCreditPair, AlbumCreditPerformer, AlbumCreditTrack, TrackInfoState, TrackInfoActions, AlbumInfoState, AlbumInfoActions, BookletState, BookletActions, SuggestionsState, SuggestionsActions, SuggestionCard, VisualizerState, ImmersiveState, ImmersiveSearchActions, ImmersiveActions, MiniPlayerState, WindowControlActions } from "state.slint";
export { HomeState, HomeActions, DiscoverState, DiscoverActions, SectionDescriptor, ConfigRow, DiscoverBrowseState, DiscoverBrowseActions, ForYouState, MixState, GenreFilterState, GenreFilterActions, AlbumState, ArtistState, NavState, ShellState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, LyricsState, LyricsLineItem, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions, LabelState, LabelActions, AwardState, AwardActions, AwardEntry, ArtistReleasesState, ArtistReleasesActions, LocationViewState, LocationViewActions, FavoritesState, FavoritesActions, PlaylistPickerState, PlaylistPickerActions, DuplicateConfirmState, DuplicateConfirmActions, PlaylistState, PlaylistActions, SidebarState, SidebarActions, SidebarFolderPopupState, CreatePlaylistState, CreatePlaylistActions, EditPlaylistState, EditPlaylistActions, CreateFolderState, CreateFolderActions, MyQbzCreateState, MyQbzCreateActions, DragState, DragActions, PlaylistManagerState, PlaylistManagerActions, OfflineManagerState, OfflineManagerActions, BlacklistState, BlacklistActions, BlacklistedArtistItem, MyQbzState, MyQbzActions, MixtapeCardItem, MyQbzAddState, MyQbzAddActions, MyQbzAddRow, MyQbzDetailState, MyQbzDetailActions, MixtapeDetailItem, MyQbzEditState, MyQbzEditActions, MyQbzMixState, MyQbzMixActions, DiscoBuilderState, DiscoBuilderActions, DiscoGroup, DiscoCandidate, LocalLibraryState, LocalLibraryActions, LibraryFoldersState, LibFolderEditState, LibraryManageActions, LibraryScanState, LibAlbumFilterState, LocalAlbumState, LocalAlbumActions, TagEditorState, TagEditorActions, FolderEditState, FolderEditActions, ToastState, TextUtil, QconnectDevState, QconnectDevice, CastState, CastDevice, CastActions, AppearanceState, MyQbzBrandingState, EphemeralPlayChoiceState, EphemeralPlayChoiceActions, PlexSettingsState, PlexAuthActions, PlexSectionItem, ScrobbleState, ScrobbleActions, DiscordState, OfflineState, OfflineModeActions, OfflineFavoritesState, OfflineFavoritesActions, ImportLogEntry, PlaylistImportState, PlaylistImportActions, DacWizardState, DacWizardActions, DacCandidateRow, RemediationRow, DacConfigRow, InfoCreditRow, InfoCreditPair, AlbumCreditPerformer, AlbumCreditTrack, TrackInfoState, TrackInfoActions, AlbumInfoState, AlbumInfoActions, BookletState, BookletActions, SuggestionsState, SuggestionsActions, SuggestionCard, VisualizerState, ImmersiveState, ImmersiveSearchActions, ImmersiveActions, MiniPlayerState, WindowControlActions, PurchasesState, PurchasesActions, PurchaseAlbumItem, PurchaseTrackItem, PurchaseAlbumGroup, PurchaseTrackGroup, PurchaseFormatItem } from "state.slint";
// Which top-level screen is shown. The app starts on `splash` while it
// restores a saved session, then resolves to `shell` or `login`.
@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
<polyline points="7 10 12 15 17 10" />
<line x1="12" x2="12" y1="15" y2="3" />
</svg>

After

Width:  |  Height:  |  Size: 324 B

@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M6 2 3 6v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V6l-3-4Z" />
<path d="M3 6h18" />
<path d="M16 10a4 4 0 0 1-8 0" />
</svg>

After

Width:  |  Height:  |  Size: 309 B

File diff suppressed because it is too large. Load diff
+13
View File
@@ -56,6 +56,7 @@ import { LabelReleasesView } from "../label/LabelReleasesView.slint";
import { LabelPageView } from "../label/LabelPageView.slint";
import { AwardView } from "../award/AwardView.slint";
import { AwardAlbumsView } from "../award/AwardAlbumsView.slint";
import { PurchasesView } from "../purchases/PurchasesView.slint";
import { ArtistsByLocationView } from "../location/ArtistsByLocationView.slint";
import { FavoritesView } from "../favorites/FavoritesView.slint";
import { FavoritesOfflineRail } from "../favorites/FavoritesOfflineRail.slint";
@@ -108,6 +109,7 @@ export component AppShell inherits Rectangle {
|| NavState.view == ContentView.label-releases
|| NavState.view == ContentView.award
|| NavState.view == ContentView.award-albums
|| NavState.view == ContentView.purchases
|| NavState.view == ContentView.location
|| NavState.view == ContentView.mix
// Playlist: LOCAL playlists and the offline sidecar rendering of a
@@ -370,6 +372,17 @@ export component AppShell inherits Rectangle {
root.open-artist(id);
}
}
if NavState.view == ContentView.purchases && !OfflineState.offline: PurchasesView {
open-album(id) => {
root.open-album(id);
}
open-artist(id) => {
root.open-artist(id);
}
media-action(kind, id, action) => {
root.media-action(kind, id, action);
}
}
if NavState.view == ContentView.playlist-manager: PlaylistManagerView { }
if NavState.view == ContentView.mixtapes: MixtapesView { }
if NavState.view == ContentView.collections: CollectionsView { }
+166 -1
View File
@@ -792,7 +792,7 @@ export global DragActions {
}
// Which content view the shell shows.
export enum ContentView { home, album, artist, artist-releases, settings, search, musician, label, label-releases, award, award-albums, location, favorites, mix, playlist, discover-browse, playlist-manager, offline-manager, blacklist-manager, local-library, local-album, mixtapes, collections, mixtape-detail, discography-builder }
export enum ContentView { home, album, artist, artist-releases, settings, search, musician, label, label-releases, award, award-albums, location, favorites, mix, playlist, discover-browse, playlist-manager, offline-manager, blacklist-manager, local-library, local-album, mixtapes, collections, mixtape-detail, discography-builder, purchases, purchase-album }
// In-app toast (transient notification). Mirrors Tauri's toastStore:
// a single toast at a time (a new one replaces the current), auto-hidden
@@ -4285,6 +4285,171 @@ export global FavoritesActions {
callback retry-load();
}
// ── Purchases (My-Purchases library surface, source-of-truth §2.1) ──
//
// A purchased album row/card. `quality-label` is the grid card's kHz form
// ("24/96 kHz"); `quality-list` is the album-list row's formatQuality form
// ("24bit/96kHz" or "CD Quality"). `purchase-date` is the SHORT-month date.
// `downloaded` only drives the hide-downloaded filter (the list view never
// shows a per-album download badge). The Rust side fills `artwork` once the
// pipeline resolves the cover.
export struct PurchaseAlbumItem {
id: string,
title: string,
artist: string,
artist-id: string,
artwork-url: string,
artwork: image,
quality-label: string, // grid card: "{bd}/{sr} kHz" ("" if either missing)
quality-list: string, // list row: "24bit/96kHz" | "CD Quality"
purchase-date: string, // SHORT month "Nov 6, 2025"
downloadable: bool,
downloaded: bool,
}
// A purchased track row. `quality` is the BARE "{bit}/{rate}" string (no kHz,
// §A.6) — "" when either field is missing. `dl-status` is the flattened
// download-store status for the row's 4-state control:
// "" | "downloading" | "complete" | "failed". `downloaded` (server registry)
// OR dl-status=="complete" both render the green redownload check.
export struct PurchaseTrackItem {
id: string,
title: string,
artist: string,
artist-id: string,
album-title: string,
album-id: string,
artwork-url: string,
artwork: image,
quality: string, // BARE "{bit}/{rate}" (§A.6); "" if either missing
duration: string, // "m:ss"
purchase-date: string, // SHORT month
streamable: bool,
downloaded: bool, // server registry downloaded flag
dl-status: string, // "" | downloading | complete | failed
}
// A group-by section for the albums tab (alpha / artist grouping).
export struct PurchaseAlbumGroup {
key: string,
title: string,
albums: [PurchaseAlbumItem],
}
// A group-by section for the tracks tab (name / artist / album grouping).
export struct PurchaseTrackGroup {
key: string,
title: string,
tracks: [PurchaseTrackItem],
}
// One option in the anchored format-picker popup (tracks-tab per-track
// download). `detail` is the "{bd}/{sr}" line shown after the label when both
// are present.
export struct PurchaseFormatItem {
id: int,
label: string,
detail: string,
}
export global PurchasesState {
// "albums" | "tracks"
in-out property <string> active-tab: "albums";
// Region-notice banner (above the nav). Shown until dismissed; the
// persisted "seen" flag seeds the initial value from Rust (Slice 12).
// Default true so a fresh session shows it, matching Tauri's
// `getUserItem('qbz-purchases-region-notice-seen') !== 'true'`.
in property <bool> show-region-notice: true;
// Search (controller-debounced 300ms). `search-query` is the live input;
// the Rust side debounces and refetches/filters.
in-out property <string> search-query: "";
in property <bool> search-active: false; // query.trim().length > 0
// Albums toolbar.
in-out property <string> album-view-mode: "grid"; // "grid" | "list"
in-out property <bool> album-grouping-enabled: false;
in-out property <string> album-group-mode: "alpha"; // "alpha" | "artist"
in-out property <string> album-sort-by: "date"; // date|artist|album|quality
in-out property <string> album-sort-direction: "desc"; // "asc" | "desc"
// Tracks toolbar.
in-out property <bool> track-grouping-enabled: false;
in-out property <string> track-group-mode: "artist"; // artist|album|name
// Filter panel (shared albums + tracks). Persisted per-user.
in-out property <bool> filter-hide-unavailable: false;
in-out property <string> filter-quality: "all"; // all|hires|cd|lossy
in-out property <bool> filter-hide-downloaded: false;
// Mutually-exclusive open menu: "" | albumGroup | albumSort | filter | trackGroup
in-out property <string> open-menu: "";
// Derived flags (computed in Rust, pushed here).
in property <bool> has-active-filters: false;
in property <int> active-filter-count: 0;
// Tab counts (server total unless search/filter active → filtered length).
in property <int> album-tab-count: 0;
in property <int> track-tab-count: 0;
// Rendered collections (already filtered/sorted/grouped in Rust). Flat
// arrays drive the non-grouped render; the *-grouped arrays drive the
// group-by render.
in property <[PurchaseAlbumItem]> albums: [];
in property <[PurchaseAlbumGroup]> albums-grouped: [];
in property <[PurchaseTrackItem]> tracks: [];
in property <[PurchaseTrackGroup]> tracks-grouped: [];
// Stable FULL artwork-target models (every loaded item, in load order).
// The artwork pipeline writes decoded covers here by index, then dual-sets
// into the rendered (filtered/sorted/grouped) models by id (the favorites
// pattern — a sort/filter/group makes the rendered models NOT share these).
// Not bound by the view; targets only.
in-out property <[PurchaseAlbumItem]> albums-full: [];
in-out property <[PurchaseTrackItem]> tracks-full: [];
// Content state.
in property <bool> loading: true;
in property <string> load-error: ""; // i18n key (purchases.*) OR raw string
// Format-picker popup (anchored). `picker-track-id` non-empty => shown.
in property <[PurchaseFormatItem]> picker-formats: [];
in property <string> picker-track-id: "";
in property <length> picker-anchor-x: 0px;
in property <length> picker-anchor-y: 0px;
// Active/playing track (mirror props) for row highlight.
in property <string> active-track-id: "";
in property <bool> playback-active: false;
}
export global PurchasesActions {
// Tabs / search.
callback select-tab(string /* albums | tracks */);
callback search(string /* query */);
callback clear-search();
// Albums toolbar.
callback set-album-group(string /* off | alpha | artist */);
callback select-album-sort(string /* date|artist|album|quality */);
callback set-album-view-mode(string /* grid | list */);
// Tracks toolbar.
callback set-track-group(string /* off | album | artist | name */);
// Filter panel.
callback set-filter-hide-unavailable(bool);
callback set-filter-quality(string /* all|hires|cd|lossy */);
callback set-filter-hide-downloaded(bool);
callback clear-all-filters();
// Menu open/close (mutually exclusive). "" closes.
callback set-open-menu(string);
// Region notice dismiss.
callback dismiss-region-notice();
// Navigation / play.
callback open-album(string /* album id */);
callback open-artist(string /* artist id */);
callback play-track(string /* track id */);
// Per-track download flow. `anchor-x`/`anchor-y` position the format
// picker; the Rust side decides 1-format (no picker) vs >1 (picker).
callback download-track(string /* track id */, length /* anchor-x */, length /* anchor-y */);
// Format-picker: a format chosen → execute the download.
callback pick-format(string /* track id */, int /* format id */);
callback close-format-picker();
// Error branch retry (re-fetch the active tab). INTENTIONALLY UNWIRED: the
// Svelte error state (PurchasesView.svelte:851-855) renders ShoppingBag +
// text with NO retry trigger, so the 1:1 EmptyBlock has no clickable retry.
// The handler in main.rs is kept as scaffolding (it would force-reload the
// active tab) so a future non-1:1 retry affordance has a seam to bind to.
callback retry();
}
// A Qobuz mix detail page (DailyQ / WeeklyQ / FavQ / TopQ), opened
// from the For You Qobuz Mixes tiles. Populated by crate::mix. Rows
// reuse the shared SearchTrackRow (with show-album), so the track