Update SongData for frontend use
This commit is contained in:
parent
ffad799f72
commit
f8bbe319bd
@ -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<i64>, total_secs: MaybeSignal<i64>) ->
|
||||
fn MediaInfo(status: RwSignal<PlayStatus>) -> 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<PlayStatus>) -> 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<PlayStatus>) -> 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");
|
||||
|
@ -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<PlayStatus>) -> impl IntoView {
|
||||
on:dragenter=move |e: DragEvent| on_drag_enter(e, index)
|
||||
on:dragover=on_drag_over
|
||||
>
|
||||
<Song song_image_path=song.image_path.clone() song_title=song.name.clone() song_artist=song.artist.clone() />
|
||||
<Song song_image_path=song.image_path.clone() song_title=song.title.clone() song_artist=Artist::display_list(&song.artists) />
|
||||
<Show
|
||||
when=move || index != 0
|
||||
fallback=|| view!{
|
||||
|
@ -1,12 +1,26 @@
|
||||
use crate::database;
|
||||
use crate::models::{Album, Artist, Song};
|
||||
|
||||
use time::Date;
|
||||
|
||||
/// Holds information about a song
|
||||
#[derive(Debug, Clone)]
|
||||
///
|
||||
/// Intended to be used in the front-end, as it includes artist and album objects, rather than just their ids.
|
||||
pub struct SongData {
|
||||
/// Song id
|
||||
pub id: i32,
|
||||
/// Song name
|
||||
pub name: String,
|
||||
/// Song artist
|
||||
pub artist: String,
|
||||
pub title: String,
|
||||
/// Song artists
|
||||
pub artists: Vec<Artist>,
|
||||
/// Song album
|
||||
pub album: String,
|
||||
pub album: Option<Album>,
|
||||
/// The track number of the song on the album
|
||||
pub track: Option<i32>,
|
||||
/// The duration of the song in seconds
|
||||
pub duration: i32,
|
||||
/// The song's release date
|
||||
pub release_date: Option<Date>,
|
||||
/// Path to song file, relative to the root of the web server.
|
||||
/// For example, `"/assets/audio/Song.mp3"`
|
||||
pub song_path: String,
|
||||
|
Loading…
x
Reference in New Issue
Block a user