feat(slint): favorites tracks search + results count
Add an expandable search over the loaded favorite tracks (title / artist / album) plus a results-count line. tracks-visible (what the list renders) derives from the full tracks set: an empty query shares the model so artwork stays live, a query forks a filtered clone carrying the already-decoded artwork (the LabelState albums/visible pattern). Adds a no-match empty state. cc
This commit is contained in:
4 files changed
+91
-4
No files matched your search
@@ -14,7 +14,7 @@ use qbz_app::shell::AppRuntime;
|
||||
use qbz_core::FrontendAdapter;
|
||||
use qbz_models::{Album, Artist, Playlist, Track};
|
||||
use serde::Deserialize;
|
||||
use slint::{ComponentHandle, ModelRc, VecModel};
|
||||
use slint::{ComponentHandle, Model, ModelRc, VecModel};
|
||||
|
||||
use crate::album_map::{self, map_album, to_item, AlbumCard};
|
||||
use crate::artwork::{ArtworkJob, ArtworkTarget};
|
||||
@@ -330,8 +330,14 @@ pub fn apply_favorites(window: &AppWindow, data: FavData) {
|
||||
album_id: t.album_id.into(),
|
||||
})
|
||||
.collect();
|
||||
state.set_tracks(ModelRc::new(VecModel::from(rows)));
|
||||
// `tracks` is the full set the artwork pipeline targets;
|
||||
// `tracks-visible` (what the list renders) shares the same
|
||||
// model until a search filter forks it, so artwork stays live.
|
||||
let model = ModelRc::new(VecModel::from(rows));
|
||||
state.set_tracks(model.clone());
|
||||
state.set_tracks_visible(model);
|
||||
state.set_tracks_total(total as i32);
|
||||
state.set_tracks_search("".into());
|
||||
}
|
||||
FavData::Albums { items, total } => {
|
||||
let cards: Vec<AlbumCardItem> = items.into_iter().map(to_item).collect();
|
||||
@@ -383,6 +389,31 @@ pub fn apply_favorites(window: &AppWindow, data: FavData) {
|
||||
state.set_loading(false);
|
||||
}
|
||||
|
||||
/// Re-derive the rendered Tracks list (`tracks-visible`) from the full
|
||||
/// `tracks` set and the search query. An empty query shares the full
|
||||
/// model so artwork keeps updating in place (the LabelState albums/visible
|
||||
/// pattern); a query forks a filtered clone (each row carries its already
|
||||
/// decoded artwork, so no re-fetch).
|
||||
pub fn derive_tracks(window: &AppWindow) {
|
||||
let state = window.global::<FavoritesState>();
|
||||
let query_owned = state.get_tracks_search().to_lowercase();
|
||||
let query = query_owned.trim();
|
||||
let all = state.get_tracks();
|
||||
if query.is_empty() {
|
||||
state.set_tracks_visible(all);
|
||||
return;
|
||||
}
|
||||
let filtered: Vec<TrackItem> = (0..all.row_count())
|
||||
.filter_map(|i| all.row_data(i))
|
||||
.filter(|t| {
|
||||
t.title.to_lowercase().contains(query)
|
||||
|| t.artist.to_lowercase().contains(query)
|
||||
|| t.album.to_lowercase().contains(query)
|
||||
})
|
||||
.collect();
|
||||
state.set_tracks_visible(ModelRc::new(VecModel::from(filtered)));
|
||||
}
|
||||
|
||||
pub fn reset_loading(window: &AppWindow) {
|
||||
window.global::<FavoritesState>().set_loading(true);
|
||||
}
|
||||
|
||||
@@ -4259,6 +4259,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
});
|
||||
}
|
||||
{
|
||||
// Local search over the loaded favorite tracks (title / artist /
|
||||
// album), re-deriving the rendered list.
|
||||
let weak = window.as_weak();
|
||||
window
|
||||
.global::<FavoritesActions>()
|
||||
.on_search_tracks(move |q| {
|
||||
if let Some(w) = weak.upgrade() {
|
||||
w.global::<FavoritesState>().set_tracks_search(q);
|
||||
favorites::derive_tracks(&w);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Artwork right-click menu wiring — Open in browser / Save as /
|
||||
// Add custom / Remove custom. Mirrors the v2_library_* + native
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
} from "../state.slint";
|
||||
import { AlbumCard } from "../discover/AlbumCard.slint";
|
||||
import { TrackRow } from "../primitives/TrackRow.slint";
|
||||
import { ExpandableSearch } from "../primitives/ExpandableSearch.slint";
|
||||
import { QbzIcon } from "../primitives/QbzIcon.slint";
|
||||
import { LoadingSpinner } from "../primitives/LoadingSpinner.slint";
|
||||
import { ListScrollbar } from "../primitives/ListScrollbar.slint";
|
||||
@@ -333,12 +334,48 @@ export component FavoritesView inherits Rectangle {
|
||||
if !FavoritesState.loading
|
||||
&& FavoritesState.active-tab == "tracks": VerticalLayout {
|
||||
spacing: 0px;
|
||||
// Toolbar — results count (left) + expandable search (right).
|
||||
if FavoritesState.tracks.length > 0: HorizontalLayout {
|
||||
spacing: 8px;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: FavoritesState.tracks-visible.length
|
||||
+ (FavoritesState.tracks-search != ""
|
||||
? " / " + FavoritesState.tracks.length
|
||||
: "")
|
||||
+ " " + @tr("tracks");
|
||||
color: Theme.text-muted;
|
||||
font-size: Typography.legal;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
ExpandableSearch {
|
||||
placeholder: @tr("Search");
|
||||
query <=> FavoritesState.tracks-search;
|
||||
edited(q) => {
|
||||
FavoritesActions.search-tracks(q);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if FavoritesState.tracks.length > 0: Rectangle { height: 12px; }
|
||||
|
||||
if FavoritesState.tracks.length == 0: Text {
|
||||
text: @tr("No favorite tracks yet.");
|
||||
color: Theme.text-muted;
|
||||
font-size: Typography.body;
|
||||
}
|
||||
for track[i] in FavoritesState.tracks: TrackRow {
|
||||
// Search filtered everything out.
|
||||
if FavoritesState.tracks.length > 0
|
||||
&& FavoritesState.tracks-visible.length == 0: Text {
|
||||
text: @tr("No tracks match your search.");
|
||||
color: Theme.text-muted;
|
||||
font-size: Typography.body;
|
||||
}
|
||||
for track[i] in FavoritesState.tracks-visible: TrackRow {
|
||||
track: track;
|
||||
index: i;
|
||||
show-artwork: true;
|
||||
|
||||
@@ -1447,8 +1447,13 @@ export global FavoritesState {
|
||||
// "tracks" | "albums" | "artists" | "playlists" | "labels"
|
||||
in-out property <string> active-tab: "tracks";
|
||||
// Tracks reuse TrackItem so the shared SearchTrackRow can
|
||||
// render them (artwork-on, per-row cover thumbnail).
|
||||
// render them (artwork-on, per-row cover thumbnail). `tracks` is the
|
||||
// full fetched set (the artwork pipeline targets it); `tracks-visible`
|
||||
// is what the list renders after the search filter (mirrors
|
||||
// LabelState.albums vs .visible).
|
||||
in property <[TrackItem]> tracks: [];
|
||||
in property <[TrackItem]> tracks-visible: [];
|
||||
in-out property <string> tracks-search: "";
|
||||
in property <[AlbumCardItem]> albums: [];
|
||||
in property <[FavoriteArtistItem]> artists: [];
|
||||
in property <[FavoritePlaylistItem]> playlists: [];
|
||||
@@ -1471,6 +1476,7 @@ export global FavoritesActions {
|
||||
callback open-playlist(string /* playlist id */);
|
||||
callback play-track(string /* track id */);
|
||||
callback track-action(string /* track id */, string /* action */);
|
||||
callback search-tracks(string /* query */);
|
||||
}
|
||||
|
||||
// A Qobuz mix detail page (DailyQ / WeeklyQ / FavQ / TopQ), opened
|
||||
|
||||
Reference in new issue
Block a user