From cf6f7b7db7b3d4a619af69fb976ac01bf171c1ce Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Fri, 15 Nov 2024 22:44:57 -0500 Subject: [PATCH] Refactor SongList/SongListExtra Don't use MaybeSignal Combine into SongListInner --- src/components/song_list.rs | 51 ++++++++++++++----------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/src/components/song_list.rs b/src/components/song_list.rs index 442b9d5..9860877 100644 --- a/src/components/song_list.rs +++ b/src/components/song_list.rs @@ -9,48 +9,35 @@ use crate::models::{Album, Artist}; const LIKE_DISLIKE_BTN_SIZE: &str = "2em"; #[component] -pub fn SongList(songs: MaybeSignal>) -> impl IntoView { - view! { - - { - songs.with(|songs| { - let mut first_song = true; - - songs.iter().map(|song| { - let playing = first_song.into(); - first_song = false; - - let extra = Option::<()>::None; - - view! { - - } - }).collect::>() - }) - } -
- } +pub fn SongList(songs: Vec) -> impl IntoView { + __SongListInner(songs.into_iter().map(|song| (song, ())).collect::>(), false) } #[component] -pub fn SongListExtra(songs: MaybeSignal>) -> impl IntoView where +pub fn SongListExtra(songs: Vec<(SongData, T)>) -> impl IntoView where + T: Clone + IntoView + 'static +{ + __SongListInner(songs, true) +} + +#[component] +fn SongListInner(songs: Vec<(SongData, T)>, show_extra: bool) -> impl IntoView where T: Clone + IntoView + 'static { view! { { - songs.with(|songs| { - let mut first_song = true; + let mut first_song = true; - songs.iter().map(|(song, extra)| { - let playing = first_song.into(); - first_song = false; + songs.iter().map(|(song, extra)| { + let playing = first_song.into(); + first_song = false; - view! { - - } - }).collect::>() - }) + view! { + + } + }).collect::>() }
}