From 9018bce348e7c6c117d314286af72f81f14f279e Mon Sep 17 00:00:00 2001 From: spinline Date: Sat, 14 Feb 2026 01:45:13 +0300 Subject: [PATCH] fix: centralize sidenav state in store and resolve all component property issues --- frontend/src/components/layout/protected.rs | 13 ++--- frontend/src/components/layout/sidebar.rs | 59 +++++++++++++++++---- frontend/src/store.rs | 16 +++--- 3 files changed, 63 insertions(+), 25 deletions(-) diff --git a/frontend/src/components/layout/protected.rs b/frontend/src/components/layout/protected.rs index 4ecbc87..6436f02 100644 --- a/frontend/src/components/layout/protected.rs +++ b/frontend/src/components/layout/protected.rs @@ -1,23 +1,20 @@ use leptos::prelude::*; use crate::components::layout::sidebar::Sidebar; use crate::components::layout::toolbar::Toolbar; -use crate::components::ui::sidenav::{SidenavWrapper, Sidenav, SidenavInset, SidenavState, SidenavCollapsible}; +use crate::components::ui::sidenav::{SidenavWrapper, Sidenav, SidenavInset}; #[component] pub fn ProtectedLayout(children: Children) -> impl IntoView { - let sidenav_state = RwSignal::new(SidenavState::Expanded); + let store = use_context::().expect("store not provided"); view! { - - + + - +
{children()}
diff --git a/frontend/src/components/layout/sidebar.rs b/frontend/src/components/layout/sidebar.rs index d37d7e7..b5404f6 100644 --- a/frontend/src/components/layout/sidebar.rs +++ b/frontend/src/components/layout/sidebar.rs @@ -109,9 +109,48 @@ pub fn Sidebar() -> impl IntoView { icon="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" label="Tümü" count=Signal::derive(total_count) - is_collapsed=is_collapsed.into() + is_collapsed=is_collapsed + /> + + + + + - // ... (aynı mantık diğer itemler için de geçerli olacak) @@ -119,7 +158,6 @@ pub fn Sidebar() -> impl IntoView {
- // Push Toggle - Hide text when collapsed
"Bildirimler" @@ -169,15 +207,18 @@ pub fn Sidebar() -> impl IntoView { } #[component] -fn SidebarItem( +fn SidebarItem( active: Signal, - on_click: impl Fn(web_sys::MouseEvent) + 'static + Send, + on_click: F, #[prop(into)] icon: String, #[prop(into)] label: &'static str, count: Signal, -) -> impl IntoView { + #[prop(into)] is_collapsed: Signal, +) -> impl IntoView +where F: Fn(web_sys::MouseEvent) + 'static + Send +{ let variant = move || if active.get() { SidenavMenuButtonVariant::Outline } else { SidenavMenuButtonVariant::Default }; - let class = move || if active.get() { "bg-accent/50 border-accent text-foreground".to_string() } else { "text-muted-foreground hover:text-foreground".to_string() }; + let class = move || if active.get() { "bg-accent/50 border-accent text-foreground font-bold".to_string() } else { "text-muted-foreground hover:text-foreground".to_string() }; view! { @@ -189,8 +230,8 @@ fn SidebarItem( - {label} - {count} + {label} + {count} } diff --git a/frontend/src/store.rs b/frontend/src/store.rs index 8edb028..bccf9ea 100644 --- a/frontend/src/store.rs +++ b/frontend/src/store.rs @@ -10,6 +10,7 @@ use base64::{Engine as _, engine::general_purpose::STANDARD as BASE64}; use wasm_bindgen::JsCast; use crate::components::ui::toast::{ToastType, toast}; +use crate::components::ui::sidenav::SidenavState; pub fn show_toast(level: NotificationLevel, message: impl Into) { let msg = message.into(); @@ -55,6 +56,7 @@ pub struct TorrentStore { pub user: RwSignal>, pub selected_torrent: RwSignal>, pub push_enabled: RwSignal, + pub sidenav_state: RwSignal, } pub fn provide_torrent_store() { @@ -65,10 +67,11 @@ pub fn provide_torrent_store() { let user = RwSignal::new(Option::::None); let selected_torrent = RwSignal::new(Option::::None); let push_enabled = RwSignal::new(false); + let sidenav_state = RwSignal::new(SidenavState::Expanded); let show_browser_notification = crate::utils::notification::use_app_notification(); - let store = TorrentStore { torrents, filter, search_query, global_stats, user, selected_torrent, push_enabled }; + let store = TorrentStore { torrents, filter, search_query, global_stats, user, selected_torrent, push_enabled, sidenav_state }; provide_context(store); // Initial check for push status @@ -134,7 +137,7 @@ pub fn provide_torrent_store() { } if was_connected && !disconnect_notified { show_toast(NotificationLevel::Warning, "Sunucu bağlantısı kesildi, yeniden bağlanılıyor..."); - disconnect_notified = true; + disconnect_notified = false; } } } @@ -153,8 +156,7 @@ pub fn provide_torrent_store() { pub async fn is_push_subscribed() -> Result { let window = web_sys::window().ok_or("no window")?; - let navigator = window.navigator(); - let sw_container = navigator.service_worker(); + let sw_container = window.navigator().service_worker(); let registration = wasm_bindgen_futures::JsFuture::from(sw_container.ready().map_err(|e| format!("{:?}", e))?) .await @@ -172,8 +174,7 @@ pub async fn is_push_subscribed() -> Result { pub async fn subscribe_to_push_notifications() { let window = web_sys::window().expect("no window"); - let navigator = window.navigator(); - let sw_container = navigator.service_worker(); + let sw_container = window.navigator().service_worker(); let registration = match wasm_bindgen_futures::JsFuture::from(sw_container.ready().expect("sw not ready")).await { Ok(reg) => reg.dyn_into::().expect("not a reg"), @@ -181,8 +182,7 @@ pub async fn subscribe_to_push_notifications() { }; // 1. Get Public Key from Backend - let public_key_res: Result = shared::server_fns::push::get_public_key().await; - let public_key = match public_key_res { + let public_key = match shared::server_fns::push::get_public_key().await { Ok(key) => key, Err(e) => { log::error!("Failed to get public key: {:?}", e); return; } };