diff --git a/frontend/src/components/layout/sidebar.rs b/frontend/src/components/layout/sidebar.rs index 00e2234..87fd4a4 100644 --- a/frontend/src/components/layout/sidebar.rs +++ b/frontend/src/components/layout/sidebar.rs @@ -3,6 +3,9 @@ use leptos::task::spawn_local; use leptos_shadcn_button::{Button, ButtonVariant, ButtonSize}; use leptos_shadcn_avatar::{Avatar, AvatarFallback}; use leptos_shadcn_separator::Separator; +use leptos::html; +use leptos_use::storage::use_local_storage; +use ::codee::string::FromToStringCodec; #[component] pub fn Sidebar() -> impl IntoView { @@ -67,6 +70,37 @@ pub fn Sidebar() -> impl IntoView { username().chars().next().unwrap_or('?').to_uppercase().to_string() }; + // --- THEME LOGIC START --- + let (current_theme, set_current_theme, _) = use_local_storage::("vibetorrent_theme"); + + // Initialize with default if empty + let current_theme_val = current_theme.get(); + if current_theme_val.is_empty() { + set_current_theme.set("dark".to_string()); + } + + // Automatically sync theme to document attribute + Effect::new(move |_| { + let theme = current_theme.get().to_lowercase(); + if let Some(doc) = document().document_element() { + let _ = doc.set_attribute("data-theme", &theme); + // Also set class for Shadcn dark mode support + if theme == "dark" || theme == "dracula" || theme == "dim" || theme == "abyss" || theme == "sunset" || theme == "cyberpunk" || theme == "nord" || theme == "business" || theme == "night" || theme == "black" || theme == "luxury" || theme == "coffee" || theme == "forest" || theme == "halloween" || theme == "synthwave" { + let _ = doc.class_list().add_1("dark"); + } else { + let _ = doc.class_list().remove_1("dark"); + } + } + }); + + let theme_details_ref = NodeRef::::new(); + let close_details = move |node_ref: NodeRef| { + if let Some(el) = node_ref.get_untracked() { + el.set_open(false); + } + }; + // --- THEME LOGIC END --- + view! {
@@ -169,6 +203,52 @@ pub fn Sidebar() -> impl IntoView {
{username}
"Online"
+ + // --- THEME BUTTON --- +
+ + + + + + + +
- } - }).collect::>() - } - -
-