From ec33b09fa9ec67a34a200777759c023d535fd1e9 Mon Sep 17 00:00:00 2001 From: ecco257 <72117210+ecco257@users.noreply.github.com> Date: Fri, 5 Apr 2024 23:46:24 -0400 Subject: [PATCH] update Song component to work for model version of Song struct --- src/lib.rs | 2 +- src/song.rs | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9765d4b..48965be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ pub mod app; pub mod auth; -pub mod songdata; pub mod playstatus; pub mod playbar; pub mod database; @@ -8,6 +7,7 @@ pub mod queue; pub mod song; pub mod models; pub mod pages; +pub mod api; pub mod users; pub mod search; use cfg_if::cfg_if; diff --git a/src/song.rs b/src/song.rs index 615cfc6..db8497f 100644 --- a/src/song.rs +++ b/src/song.rs @@ -1,13 +1,30 @@ use leptos::*; +use crate::api::songs::get_artists; #[component] -pub fn Song(song_image_path: String, song_title: String, song_artist: String) -> impl IntoView { +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()); + // 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 + }); + view!{
{song_title.clone()}

{song_title}

-

{song_artist}

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

{artists_string}

+ }) + }} +
}