diff --git a/src/song.rs b/src/song.rs index db8497f..aed7f6e 100644 --- a/src/song.rs +++ b/src/song.rs @@ -1,11 +1,17 @@ use leptos::*; +use leptos::logging::*; use crate::api::songs::get_artists; #[component] pub fn Song(song_id_arg: Option, song_image_path: String, song_title: String) -> impl IntoView { - let song_artists_resource = create_resource(|| (), move |_| async move { - let artists_vec = get_artists(song_id_arg).await.unwrap_or(Vec::new()); + let song_id = Signal::derive(move || song_id_arg); + + let song_artists_resource = create_resource(song_id, move |song_id| async move { + let artists_vec = get_artists(song_id).await.unwrap_or_else(|_| { + warn!("Error when searching for artists for song"); + Vec::new() + }); // convert the vec of artists to a string of artists separated by commas let artists_string = artists_vec.iter().map(|artist| artist.name.clone()).collect::>().join(", "); artists_string @@ -17,11 +23,16 @@ pub fn Song(song_id_arg: Option, song_image_path: String, song_title: Strin

{song_title}

Loading... } + fallback=move || view! {

""

} > {move || { - song_artists_resource.get().map(|artists_string| view! { -

{artists_string}

+ song_artists_resource.get().map(|artists_string| { + if artists_string.is_empty() { + view! {

""

} + } + else { + view! {

{artists_string}

} + } }) }}