Refactor SongList/SongListExtra

Don't use MaybeSignal
Combine into SongListInner
This commit is contained in:
Ethan Girouard 2024-11-15 22:44:57 -05:00
parent 8f01ff24d8
commit cf6f7b7db7
Signed by: eta357
GPG Key ID: 7BCDC36DFD11C146

View File

@ -9,37 +9,24 @@ use crate::models::{Album, Artist};
const LIKE_DISLIKE_BTN_SIZE: &str = "2em"; const LIKE_DISLIKE_BTN_SIZE: &str = "2em";
#[component] #[component]
pub fn SongList(songs: MaybeSignal<Vec<SongData>>) -> impl IntoView { pub fn SongList(songs: Vec<SongData>) -> impl IntoView {
view! { __SongListInner(songs.into_iter().map(|song| (song, ())).collect::<Vec<_>>(), false)
<table class="song-list">
{
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! {
<SongListItem song={song.clone()} song_playing=playing extra />
}
}).collect::<Vec<_>>()
})
}
</table>
}
} }
#[component] #[component]
pub fn SongListExtra<T>(songs: MaybeSignal<Vec<(SongData, T)>>) -> impl IntoView where pub fn SongListExtra<T>(songs: Vec<(SongData, T)>) -> impl IntoView where
T: Clone + IntoView + 'static
{
__SongListInner(songs, true)
}
#[component]
fn SongListInner<T>(songs: Vec<(SongData, T)>, show_extra: bool) -> impl IntoView where
T: Clone + IntoView + 'static T: Clone + IntoView + 'static
{ {
view! { view! {
<table class="song-list"> <table class="song-list">
{ {
songs.with(|songs| {
let mut first_song = true; let mut first_song = true;
songs.iter().map(|(song, extra)| { songs.iter().map(|(song, extra)| {
@ -47,10 +34,10 @@ pub fn SongListExtra<T>(songs: MaybeSignal<Vec<(SongData, T)>>) -> impl IntoView
first_song = false; first_song = false;
view! { view! {
<SongListItem song={song.clone()} song_playing=playing extra=Some(extra.clone()) /> <SongListItem song={song.clone()} song_playing=playing
extra={if show_extra { Some(extra.clone()) } else { None }} />
} }
}).collect::<Vec<_>>() }).collect::<Vec<_>>()
})
} }
</table> </table>
} }