feat(discover): add "queue" + "create playlist" buttons to Weekly rows
Add two title-adjacent icon buttons to the external-reco Weekly
Exploration and Weekly Jams rows: add the whole backing track list to the
queue, or create a playlist from it (reusing the add-to-playlist picker
from the queue save-as-playlist work, P6). SlimCarousel gains an opt-in
show-list-actions + list-action callback (default off, so the shared
recent/popular rows are unchanged); external_reco::list_track_ids reads
the row's backing ids; playback::enqueue_track_ids resolves + enqueues
them; a new ("ext-reco-list", _) media-action routes both.
cc
This commit is contained in:
5 files changed
+112
-1
No files matched your search
@@ -90,6 +90,10 @@ export component ExternalRecoView inherits VerticalLayout {
|
|||||||
if ExternalRecoState.weekly-exploration.length > 0: SlimCarousel {
|
if ExternalRecoState.weekly-exploration.length > 0: SlimCarousel {
|
||||||
title: @tr("Weekly Exploration");
|
title: @tr("Weekly Exploration");
|
||||||
items: ExternalRecoState.weekly-exploration;
|
items: ExternalRecoState.weekly-exploration;
|
||||||
|
show-list-actions: true;
|
||||||
|
list-action(action) => {
|
||||||
|
root.media-action("ext-reco-list", "weekly-exploration", action);
|
||||||
|
}
|
||||||
item-clicked(id) => {
|
item-clicked(id) => {
|
||||||
root.play-track(id);
|
root.play-track(id);
|
||||||
}
|
}
|
||||||
@@ -99,6 +103,10 @@ export component ExternalRecoView inherits VerticalLayout {
|
|||||||
if ExternalRecoState.weekly-jams.length > 0: SlimCarousel {
|
if ExternalRecoState.weekly-jams.length > 0: SlimCarousel {
|
||||||
title: @tr("Weekly Jams");
|
title: @tr("Weekly Jams");
|
||||||
items: ExternalRecoState.weekly-jams;
|
items: ExternalRecoState.weekly-jams;
|
||||||
|
show-list-actions: true;
|
||||||
|
list-action(action) => {
|
||||||
|
root.media-action("ext-reco-list", "weekly-jams", action);
|
||||||
|
}
|
||||||
item-clicked(id) => {
|
item-clicked(id) => {
|
||||||
root.play-track(id);
|
root.play-track(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,11 @@ export component SlimCarousel inherits VerticalLayout {
|
|||||||
in property <string> title;
|
in property <string> title;
|
||||||
in property <[SlimItem]> items;
|
in property <[SlimItem]> items;
|
||||||
callback item-clicked(string);
|
callback item-clicked(string);
|
||||||
|
// P7: optional title-adjacent list actions ("add to queue" / "create
|
||||||
|
// playlist from this list"). Off by default so the shared SlimCarousel rows
|
||||||
|
// (recent, popular) are unchanged; only the Weekly rows opt in.
|
||||||
|
in property <bool> show-list-actions: false;
|
||||||
|
callback list-action(string);
|
||||||
|
|
||||||
property <int> columns: 4;
|
property <int> columns: 4;
|
||||||
property <int> rows: 3;
|
property <int> rows: 3;
|
||||||
@@ -71,6 +76,29 @@ export component SlimCarousel inherits VerticalLayout {
|
|||||||
vertical-alignment: center;
|
vertical-alignment: center;
|
||||||
horizontal-stretch: 1;
|
horizontal-stretch: 1;
|
||||||
}
|
}
|
||||||
|
// Title-adjacent list actions (P7): add the whole backing list to the
|
||||||
|
// queue / create a playlist from it. Icon buttons (ADR-008, no pills).
|
||||||
|
if root.show-list-actions: HorizontalLayout {
|
||||||
|
spacing: 4px;
|
||||||
|
VerticalLayout {
|
||||||
|
alignment: center;
|
||||||
|
NavButton {
|
||||||
|
icon: @image-url("../assets/icons/list-end.svg");
|
||||||
|
clicked => {
|
||||||
|
root.list-action("queue");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
VerticalLayout {
|
||||||
|
alignment: center;
|
||||||
|
NavButton {
|
||||||
|
icon: @image-url("../assets/icons/list-music.svg");
|
||||||
|
clicked => {
|
||||||
|
root.list-action("create-playlist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Only when there is a second page.
|
// Only when there is a second page.
|
||||||
if root.total > root.per-page: HorizontalLayout {
|
if root.total > root.per-page: HorizontalLayout {
|
||||||
spacing: 4px;
|
spacing: 4px;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use qbz_external_reco::{
|
|||||||
};
|
};
|
||||||
use qbz_integrations::{LastFmClient, ListenBrainzClient, MusicBrainzClient};
|
use qbz_integrations::{LastFmClient, ListenBrainzClient, MusicBrainzClient};
|
||||||
use qbz_models::{Album, Artist, Track};
|
use qbz_models::{Album, Artist, Track};
|
||||||
use slint::{ComponentHandle, ModelRc, VecModel};
|
use slint::{ComponentHandle, Model, ModelRc, VecModel};
|
||||||
|
|
||||||
use crate::adapter::SlintAdapter;
|
use crate::adapter::SlintAdapter;
|
||||||
use crate::artwork::{ArtworkJob, ArtworkTarget, ImageCache};
|
use crate::artwork::{ArtworkJob, ArtworkTarget, ImageCache};
|
||||||
@@ -335,6 +335,22 @@ enum TrackRow {
|
|||||||
WeeklyJams,
|
WeeklyJams,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Read the backing Qobuz track ids of one external-reco Weekly TRACK row
|
||||||
|
/// (Weekly Exploration / Weekly Jams) for the P7 title-adjacent buttons.
|
||||||
|
/// Returns the whole backing list (not just the 24 visible), in row order.
|
||||||
|
pub fn list_track_ids(window: &AppWindow, section: &str) -> Vec<u64> {
|
||||||
|
let s = window.global::<ExternalRecoState>();
|
||||||
|
let model = match section {
|
||||||
|
"weekly-exploration" => s.get_weekly_exploration(),
|
||||||
|
"weekly-jams" => s.get_weekly_jams(),
|
||||||
|
_ => return Vec::new(),
|
||||||
|
};
|
||||||
|
model
|
||||||
|
.iter()
|
||||||
|
.filter_map(|it| it.id.as_str().parse::<u64>().ok())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
fn slim_from_artist(a: &ArtistReco) -> SlimItem {
|
fn slim_from_artist(a: &ArtistReco) -> SlimItem {
|
||||||
SlimItem {
|
SlimItem {
|
||||||
id: a.qobuz_artist_id.to_string().into(),
|
id: a.qobuz_artist_id.to_string().into(),
|
||||||
|
|||||||
@@ -8278,6 +8278,36 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
handle.clone(),
|
handle.clone(),
|
||||||
id.clone(),
|
id.clone(),
|
||||||
),
|
),
|
||||||
|
// External-reco Weekly rows (P7): the title-adjacent buttons.
|
||||||
|
// `id` carries the section key ("weekly-exploration"/"weekly-jams").
|
||||||
|
("ext-reco-list", "queue") => {
|
||||||
|
if let Some(w) = weak.upgrade() {
|
||||||
|
let ids = external_reco::list_track_ids(&w, &id);
|
||||||
|
playback::enqueue_track_ids(
|
||||||
|
runtime.clone(),
|
||||||
|
weak.clone(),
|
||||||
|
handle.clone(),
|
||||||
|
ids,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
("ext-reco-list", "create-playlist") => {
|
||||||
|
if let Some(w) = weak.upgrade() {
|
||||||
|
let ids = external_reco::list_track_ids(&w, &id);
|
||||||
|
if !ids.is_empty() {
|
||||||
|
let ids_str: Vec<String> =
|
||||||
|
ids.iter().map(|i| i.to_string()).collect();
|
||||||
|
playlist_picker::open_for_ids(
|
||||||
|
&w,
|
||||||
|
runtime.clone(),
|
||||||
|
&handle,
|
||||||
|
ids_str,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
("track", "add-to-playlist") => {
|
("track", "add-to-playlist") => {
|
||||||
// Open the global picker for this track + load the
|
// Open the global picker for this track + load the
|
||||||
// user's playlists. SOURCE-TYPED routing first: this
|
// user's playlists. SOURCE-TYPED routing first: this
|
||||||
|
|||||||
@@ -3172,6 +3172,35 @@ pub fn enqueue_playlist(
|
|||||||
|
|
||||||
/// Append (or insert-next) a batch of already-fetched tracks to the queue
|
/// Append (or insert-next) a batch of already-fetched tracks to the queue
|
||||||
/// without re-fetching them. Used by the favorites bulk bar.
|
/// without re-fetching them. Used by the favorites bulk bar.
|
||||||
|
/// Resolve a list of Qobuz track ids (order-preserving) and enqueue them at the
|
||||||
|
/// end of the queue (or play-next). Backs the external-reco Weekly rows'
|
||||||
|
/// "add to queue" button (P7). Toasts the outcome.
|
||||||
|
pub fn enqueue_track_ids(
|
||||||
|
runtime: Runtime,
|
||||||
|
weak: slint::Weak<AppWindow>,
|
||||||
|
handle: tokio::runtime::Handle,
|
||||||
|
ids: Vec<u64>,
|
||||||
|
next: bool,
|
||||||
|
) {
|
||||||
|
if ids.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handle.spawn(async move {
|
||||||
|
match runtime.core().get_tracks_batch(&ids).await {
|
||||||
|
Ok(tracks) if !tracks.is_empty() => {
|
||||||
|
let n = tracks.len();
|
||||||
|
enqueue_tracks(runtime, tokio::runtime::Handle::current(), tracks, next);
|
||||||
|
crate::toast::success_weak(&weak, format!("Added {n} tracks to queue"));
|
||||||
|
}
|
||||||
|
Ok(_) => crate::toast::error_weak(&weak, "No tracks to add"),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("[qbz-slint] enqueue_track_ids: get_tracks_batch failed: {e}");
|
||||||
|
crate::toast::error_weak(&weak, "Failed to add tracks");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub fn enqueue_tracks(
|
pub fn enqueue_tracks(
|
||||||
runtime: Runtime,
|
runtime: Runtime,
|
||||||
handle: tokio::runtime::Handle,
|
handle: tokio::runtime::Handle,
|
||||||
|
|||||||
Reference in new issue
Block a user