diff --git a/src/components/sidebar.rs b/src/components/sidebar.rs index cfbf883..8e622f8 100644 --- a/src/components/sidebar.rs +++ b/src/components/sidebar.rs @@ -1,6 +1,15 @@ +use crate::components::error::Error; +use crate::components::loading::*; use crate::components::menu::*; +use crate::util::state::GlobalState; +use leptos::html::Div; use leptos::prelude::*; use leptos_icons::*; +use leptos_router::components::{Form, A}; +use leptos_router::hooks::use_location; +use leptos_use::{on_click_outside_with_options, OnClickOutsideOptions}; +use std::sync::Arc; +use web_sys::Response; #[component] pub fn Sidebar( @@ -9,7 +18,7 @@ pub fn Sidebar( add_album_open: RwSignal, ) -> impl IntoView { view! { -
+
@@ -17,18 +26,143 @@ pub fn Sidebar( } #[component] -pub fn Playlists() -> impl IntoView { +fn AddPlaylistDialog(open: RwSignal, node_ref: NodeRef
) -> impl IntoView { + let playlist_name = RwSignal::new("".to_string()); + let loading = RwSignal::new(false); + let error_msg = RwSignal::new(None); + + let handle_response = Arc::new(move |response: &Response| { + loading.set(false); + + if response.ok() { + open.set(false); + GlobalState::playlists().refetch(); + } else { + error_msg.set(Some("Failed to create playlist".to_string())); + } + }); + view! { -
-
-

Playlists

- +
+ +
+
+ + + + +
- New Playlist - + + {move || { + error_msg.get().map(|error| { + view! { + + message=error.clone() + /> + } + }) + }} + +
+ +
+
-
+ + } +} + +#[component] +pub fn Playlists() -> impl IntoView { + let location = use_location(); + + let add_playlist_open = RwSignal::new(false); + + let create_playlist = move |_| { + leptos::logging::log!("Creating playlist"); + add_playlist_open.set(true); + }; + + let add_playlist_dialog = NodeRef::
::new(); + + let _dialog_close_handler = on_click_outside_with_options( + add_playlist_dialog, + move |_| add_playlist_open.set(false), + OnClickOutsideOptions::default().ignore(["#add-playlist-dialog-btn"]), + ); + + view! { +
+
+

"Playlists"

+ +
+
+ } + > + + message=error.to_string() + /> + } + }).collect::>() + } + > + {move || GlobalState::playlists().get().map(|playlists| { + playlists.map(|playlists| { + + view! { + {playlists.into_iter().map(|playlist| { + let active = Signal::derive(move || { + location.pathname.get().ends_with(&format!("/playlist/{}", playlist.id)) + }); + + view! { + + +

{playlist.name}

+
+ } + }).collect::>()} + } + }) + })} +
+
+
+
+ + + + } }