From f8bbe319bd602ba5553947ca1dda0c54c760d72e Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Tue, 23 Jul 2024 23:31:48 -0400 Subject: [PATCH] Update SongData for frontend use --- src/playbar.rs | 12 +++++++----- src/queue.rs | 3 ++- src/songdata.rs | 24 +++++++++++++++++++----- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/playbar.rs b/src/playbar.rs index c90df53..7ff2458 100644 --- a/src/playbar.rs +++ b/src/playbar.rs @@ -1,3 +1,4 @@ +use crate::models::Artist; use crate::playstatus::PlayStatus; use leptos::ev::MouseEvent; use leptos::html::{Audio, Div}; @@ -243,19 +244,20 @@ fn PlayDuration(elapsed_secs: MaybeSignal, total_secs: MaybeSignal) -> fn MediaInfo(status: RwSignal) -> impl IntoView { let name = Signal::derive(move || { status.with(|status| { - status.queue.front().map_or("No media playing".into(), |song| song.name.clone()) + status.queue.front().map_or("No media playing".into(), |song| song.title.clone()) }) }); let artist = Signal::derive(move || { status.with(|status| { - status.queue.front().map_or("".into(), |song| song.artist.clone()) + status.queue.front().map_or("".into(), |song| format!("{}", Artist::display_list(&song.artists))) }) }); let album = Signal::derive(move || { status.with(|status| { - status.queue.front().map_or("".into(), |song| song.album.clone()) + status.queue.front().map_or("".into(), |song| + song.album.as_ref().map_or("".into(), |album| album.title.clone())) }) }); @@ -400,7 +402,7 @@ pub fn PlayBar(status: RwSignal) -> impl IntoView { status.with_untracked(|status| { // Start playing the first song in the queue, if available if let Some(song) = status.queue.front() { - log!("Starting playing with song: {}", song.name); + log!("Starting playing with song: {}", song.title); // Don't use the set_play_src / set_playing helper function // here because we already have access to the audio element @@ -453,7 +455,7 @@ pub fn PlayBar(status: RwSignal) -> impl IntoView { let prev_song = status.queue.pop_front(); if let Some(prev_song) = prev_song { - log!("Adding song to history: {}", prev_song.name); + log!("Adding song to history: {}", prev_song.title); status.history.push_back(prev_song); } else { log!("Queue empty, no previous song to add to history"); diff --git a/src/queue.rs b/src/queue.rs index 39f0ee0..8a819b9 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -1,3 +1,4 @@ +use crate::models::Artist; use crate::playstatus::PlayStatus; use crate::song::Song; use leptos::ev::MouseEvent; @@ -98,7 +99,7 @@ pub fn Queue(status: RwSignal) -> impl IntoView { on:dragenter=move |e: DragEvent| on_drag_enter(e, index) on:dragover=on_drag_over > - + , /// Song album - pub album: String, + pub album: Option, + /// The track number of the song on the album + pub track: Option, + /// The duration of the song in seconds + pub duration: i32, + /// The song's release date + pub release_date: Option, /// Path to song file, relative to the root of the web server. /// For example, `"/assets/audio/Song.mp3"` pub song_path: String,