fixed state management bug
This commit is contained in:
parent
4d734ef594
commit
f311994058
@ -2,9 +2,11 @@ use leptos::*;
|
||||
use leptos_icons::*;
|
||||
use leptos::leptos_dom::*;
|
||||
use crate::api::playlists::create_playlist;
|
||||
use crate::api::playlists::get_playlists;
|
||||
use crate::models::Playlist;
|
||||
|
||||
#[component]
|
||||
pub fn CreatePlayList(closer: WriteSignal<bool>) -> impl IntoView {
|
||||
pub fn CreatePlayList(closer: WriteSignal<bool>, set_playlists: WriteSignal<Vec<Playlist>>) -> impl IntoView {
|
||||
|
||||
let (playlist_name, set_playlist_name) = create_signal("".to_string());
|
||||
|
||||
@ -20,6 +22,13 @@ pub fn CreatePlayList(closer: WriteSignal<bool>) -> impl IntoView {
|
||||
log!("Playlist created successfully!");
|
||||
closer.update(|value| *value = false);
|
||||
}
|
||||
let playlists = get_playlists().await;
|
||||
if let Err(err) = playlists {
|
||||
// Handle the error here, e.g., log it or display to the user
|
||||
log!("Error getting playlists: {:?}", err);
|
||||
} else {
|
||||
set_playlists.update(|value| *value = playlists.unwrap());
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
|
@ -90,7 +90,7 @@ pub fn PlayListPopUp(playlist: Playlist, set_show_playlist: WriteSignal<bool>) -
|
||||
</div>
|
||||
<ul class="songs">
|
||||
{
|
||||
move || songs.get().iter().enumerate().map(|(index,song)| view! {
|
||||
move || songs.get().iter().enumerate().map(|(_index,song)| view! {
|
||||
<PlaylistSong song=song.clone() playlist_id=playlist.id.clone() set_songs=set_songs />
|
||||
}).collect::<Vec<_>>()
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ pub fn Playlists() -> impl IntoView {
|
||||
let (playlists, set_playlists) = create_signal(vec![]);
|
||||
|
||||
create_effect(move |_| {
|
||||
|
||||
spawn_local(async move {
|
||||
let playlists2 = get_playlists().await;
|
||||
if let Err(err) = playlists2 {
|
||||
@ -38,12 +37,12 @@ pub fn Playlists() -> impl IntoView {
|
||||
when=move || create_playlist_open()
|
||||
fallback=move || view! {<div></div>}
|
||||
>
|
||||
<CreatePlayList closer=set_create_playlist_open/>
|
||||
<CreatePlayList closer=set_create_playlist_open set_playlists=set_playlists/>
|
||||
</Show>
|
||||
|
||||
<ul class="playlists">
|
||||
{
|
||||
move || playlists.get().iter().enumerate().map(|(index,playlist)| view! {
|
||||
move || playlists.get().iter().enumerate().map(|(_index,playlist)| view! {
|
||||
<Playlist playlist=playlist.clone() />
|
||||
}).collect::<Vec<_>>()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user