Refactor SongList/SongListExtra
Don't use MaybeSignal Combine into SongListInner
This commit is contained in:
parent
8f01ff24d8
commit
cf6f7b7db7
@ -9,48 +9,35 @@ 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)| {
|
||||||
let playing = first_song.into();
|
let playing = first_song.into();
|
||||||
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>
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user