feat(slint): search box for the favorites Labels tab

Add an ExpandableSearch to the Labels toolbar (mirrors tracks/albums),
wired to labels-search + the new derive_labels controller fn, which
forks a name-filtered clone of the loaded labels and shares the full
model when the query is empty (artwork stays live). apply_favorites now
derives the visible set on load.

cc
This commit is contained in:
vicrodh committed 2026-05-27 13:19:33 -06:00
1 parent d731c17f31
commit 5240cf6e41
4 files changed
+52 -2

No files matched your search

+23 -2
View File
@@ -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::<FavoritesState>();
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<FavoriteLabelItem> = (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<Track> {
FAV_CURRENT.lock().map(|c| c.clone()).unwrap_or_default()
+12
View File
@@ -4506,6 +4506,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
});
}
{
// Local search over the loaded favorite labels (name).
let weak = window.as_weak();
window
.global::<FavoritesActions>()
.on_search_labels(move |q| {
if let Some(w) = weak.upgrade() {
w.global::<FavoritesState>().set_labels_search(q);
favorites::derive_labels(&w);
}
});
}
{
// Group the favorite tracks (off / album / artist / name).
let weak = window.as_weak();
@@ -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; }
+2
View File
@@ -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 <string> labels-search: "";
in property <int> tracks-total: 0;
in property <int> albums-total: 0;
in property <int> 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 */);