feat(queue): wire "Save as playlist" to the add-to-playlist picker

The queue footer button fired a correctly-wired callback whose handler
was a stub that only logged "modal pending". Replace it with the faithful
Tauri behavior: resolve the queue's tracks (current + upcoming,
de-duplicated) and open the add-to-playlist picker seeded with them, so
the inline "Create new playlist" row turns the queue into a named
playlist and picking an existing one appends to it.

Add a reusable playlist_picker::open_for_ids(window, runtime, handle,
ids, local) that dedups the open_multi + load + apply idiom; it is also
the entry point the reco-row buttons (P7) reuse.

cc
This commit is contained in:
vicrodh committed 2026-06-27 13:37:27 -06:00
1 parent 6520c007ae
commit b89009c254
2 files changed
+45 -11

No files matched your search

+26
View File
@@ -2,6 +2,8 @@
//! into PlaylistPickerState for the global picker modal; the pick
//! handler in main.rs adds the pending track to the chosen playlist.
use std::sync::Arc;
use qbz_app::shell::AppRuntime;
use qbz_core::FrontendAdapter;
use slint::{ComponentHandle, ModelRc, VecModel};
@@ -113,3 +115,27 @@ pub fn apply(window: &AppWindow, playlists: Vec<PickPlaylist>) {
state.set_filter("".into());
state.set_loading(false);
}
/// Open the Add-to-Playlist picker seeded with `ids` and asynchronously
/// populate the user's playlists. Picking an existing playlist appends the
/// ids to it; the inline "Create new playlist" row create-and-adds them — so
/// this is the single entry point for "create/add a playlist from an arbitrary
/// track-id list" (the queue save-as-playlist + the reco rows). MUST be called
/// on the UI/event-loop thread (it sets Slint globals). `local=false` -> Qobuz
/// u64 ids as strings; `local=true` -> LocalLibrary/Plex refs.
pub fn open_for_ids<A>(
window: &AppWindow,
runtime: Arc<AppRuntime<A>>,
handle: &tokio::runtime::Handle,
ids: Vec<String>,
local: bool,
) where
A: FrontendAdapter + Send + Sync + 'static,
{
open_multi(window, &ids, local);
let weak = window.as_weak();
handle.spawn(async move {
let playlists = load(&runtime).await;
let _ = weak.upgrade_in_event_loop(move |w| apply(&w, playlists));
});
}
+19 -11
View File
@@ -789,8 +789,11 @@ impl QueueController {
});
}
/// The current queue track IDs (current + upcoming), in play order —
/// the set the "save as playlist" action would persist.
/// Open the Add-to-Playlist picker seeded with the queue's tracks
/// (current + upcoming, de-duplicated, in play order). The picker's inline
/// "Create new playlist" row turns the queue into a named playlist; picking
/// an existing one appends the queue to it. Mirrors Tauri's
/// handleSaveQueueAsPlaylist (which reuses the add-to-playlist modal).
pub fn save_as_playlist(&self) {
let this = self.clone();
self.handle.spawn(async move {
@@ -799,15 +802,20 @@ impl QueueController {
if let Some(curr) = state.current_track.as_ref() {
ids.push(curr.id);
}
ids.extend(state.upcoming.iter().map(|t| t.id));
// The Slint MVP has no playlist-name input modal yet, so the
// queue cannot be persisted into a named playlist here. Log the
// resolved track set so the wiring is verifiable; the modal is
// tracked as follow-up work.
log::info!(
"[qbz-slint] queue: save-as-playlist requested for {} tracks (modal pending)",
ids.len()
);
for t in state.upcoming.iter() {
if !ids.contains(&t.id) {
ids.push(t.id);
}
}
if ids.is_empty() {
return;
}
let ids_str: Vec<String> = ids.iter().map(|id| id.to_string()).collect();
let runtime = this.runtime.clone();
let handle = this.handle.clone();
let _ = this.weak.upgrade_in_event_loop(move |w| {
crate::playlist_picker::open_for_ids(&w, runtime, &handle, ids_str, false);
});
});
}