diff --git a/crates/qbz-slint/src/favorites.rs b/crates/qbz-slint/src/favorites.rs index ff5a732a8..cabb3785c 100644 --- a/crates/qbz-slint/src/favorites.rs +++ b/crates/qbz-slint/src/favorites.rs @@ -508,9 +508,10 @@ pub fn apply_favorites(window: &AppWindow, data: FavData) { // `labels-visible` (what the grid renders) shares it until a // search filter forks it, so artwork stays live. let model = ModelRc::new(VecModel::from(rows)); - state.set_labels(model.clone()); - state.set_labels_visible(model); + state.set_labels(model); state.set_labels_total(total as i32); + state.set_labels_search("".into()); + derive_labels(window); } } state.set_loading(false); @@ -580,6 +581,26 @@ pub fn derive_tracks(window: &AppWindow) { state.set_tracks_visible(ModelRc::new(VecModel::from(filtered))); } +/// Re-derive the rendered Labels grid (`labels-visible`) from the full +/// `labels` set and the search query. An empty query shares the full +/// model so artwork keeps updating in place; a query forks a filtered +/// clone (name-only substring match, mirrors Tauri's filteredLabels). +pub fn derive_labels(window: &AppWindow) { + let state = window.global::(); + let query_owned = state.get_labels_search().to_lowercase(); + let query = query_owned.trim(); + let all = state.get_labels(); + if query.is_empty() { + state.set_labels_visible(all); + return; + } + let filtered: Vec = (0..all.row_count()) + .filter_map(|i| all.row_data(i)) + .filter(|l| l.name.to_lowercase().contains(query)) + .collect(); + state.set_labels_visible(ModelRc::new(VecModel::from(filtered))); +} + /// The loaded favorite tracks as a play-ready queue (Play all). pub fn play_tracks() -> Vec { FAV_CURRENT.lock().map(|c| c.clone()).unwrap_or_default() diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index 8fdcd5cd7..a06b68b76 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -4506,6 +4506,18 @@ fn main() -> Result<(), Box> { } }); } + { + // Local search over the loaded favorite labels (name). + let weak = window.as_weak(); + window + .global::() + .on_search_labels(move |q| { + if let Some(w) = weak.upgrade() { + w.global::().set_labels_search(q); + favorites::derive_labels(&w); + } + }); + } { // Group the favorite tracks (off / album / artist / name). let weak = window.as_weak(); diff --git a/crates/qbz-slint/ui/favorites/FavoritesView.slint b/crates/qbz-slint/ui/favorites/FavoritesView.slint index 20fcbf2a8..9c9935628 100644 --- a/crates/qbz-slint/ui/favorites/FavoritesView.slint +++ b/crates/qbz-slint/ui/favorites/FavoritesView.slint @@ -614,6 +614,21 @@ export component FavoritesView inherits Rectangle { ViewToggle { } } } + if FavoritesState.active-tab == "labels" + && FavoritesState.labels.length > 0: HorizontalLayout { + spacing: 8px; + VerticalLayout { + alignment: center; + ExpandableSearch { + placeholder: @tr("Search"); + sm: true; + query <=> FavoritesState.labels-search; + edited(q) => { + FavoritesActions.search-labels(q); + } + } + } + } } Rectangle { height: 14px; } diff --git a/crates/qbz-slint/ui/state.slint b/crates/qbz-slint/ui/state.slint index 8990a8aa5..3a3f1c8ff 100644 --- a/crates/qbz-slint/ui/state.slint +++ b/crates/qbz-slint/ui/state.slint @@ -1489,6 +1489,7 @@ export global FavoritesState { in property <[FavoritePlaylistItem]> playlists: []; in property <[FavoriteLabelItem]> labels: []; in property <[FavoriteLabelItem]> labels-visible: []; // after search filter (rendered) + in-out property labels-search: ""; in property tracks-total: 0; in property albums-total: 0; in property artists-total: 0; @@ -1516,6 +1517,7 @@ export global FavoritesActions { callback bulk-action(string /* select-all | remove-selected | clear */); callback album-action(string /* album id */, string /* action */); callback albums-search(string /* query */); + callback search-labels(string /* query */); callback albums-set-view(string /* grid | list */); callback albums-set-sort(string /* sort key */); callback albums-set-group(string /* off | alpha | artist */);