feat(slint): wire header search input with debounced live search
The header TextInput now submits on Enter (records history, opens the results page) and live-searches on edit. Live search debounces 300 ms via a Slint Timer and requires 2+ characters. A monotonic version counter guards navigate_search so a stale load cannot overwrite newer results. cc
This commit is contained in:
3 files changed
+98
-5
No files matched your search
@@ -14,6 +14,27 @@ use slint::{ComponentHandle, ModelRc, VecModel};
|
||||
|
||||
use crate::{AlbumCardItem, AppWindow, SearchPlaylistItem, SearchState, SearchTrackItem, SlimItem};
|
||||
|
||||
thread_local! {
|
||||
/// Monotonic search-attempt counter. Each `navigate_search` captures the
|
||||
/// current value; a stale async load whose version is no longer current
|
||||
/// must not overwrite a newer search's results. UI thread only.
|
||||
static SEARCH_VERSION: std::cell::Cell<u64> = std::cell::Cell::new(0);
|
||||
}
|
||||
|
||||
/// Bump the search version and return the new value.
|
||||
pub fn next_search_version() -> u64 {
|
||||
SEARCH_VERSION.with(|c| {
|
||||
let v = c.get() + 1;
|
||||
c.set(v);
|
||||
v
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether `version` is still the most recent search attempt.
|
||||
pub fn is_current_version(version: u64) -> bool {
|
||||
SEARCH_VERSION.with(|c| c.get() == version)
|
||||
}
|
||||
|
||||
// ==================== Plain (Send) row types ====================
|
||||
|
||||
/// An album result row, before it becomes a Slint `AlbumCardItem`.
|
||||
|
||||
Reference in new issue
Block a user