use leptos::prelude::*; use leptos::task::spawn_local; use crate::components::ui::sidenav::*; use crate::components::ui::button::{Button, ButtonVariant, ButtonSize}; use crate::components::ui::theme_toggle::ThemeToggle; use crate::components::ui::switch::Switch; #[component] pub fn Sidebar() -> impl IntoView { let store = use_context::().expect("store not provided"); let total_count = move || store.torrents.with(|map| map.len()); let downloading_count = move || { store.torrents.with(|map| { map.values() .filter(|t| t.status == shared::TorrentStatus::Downloading) .count() }) }; let seeding_count = move || { store.torrents.with(|map| { map.values() .filter(|t| t.status == shared::TorrentStatus::Seeding) .count() }) }; let completed_count = move || { store.torrents.with(|map| { map.values() .filter(|t| { t.status == shared::TorrentStatus::Seeding || (t.status == shared::TorrentStatus::Paused && t.percent_complete >= 100.0) }) .count() }) }; let paused_count = move || { store.torrents.with(|map| { map.values() .filter(|t| t.status == shared::TorrentStatus::Paused) .count() }) }; let inactive_count = move || { store.torrents.with(|map| { map.values() .filter(|t| { t.status == shared::TorrentStatus::Paused || t.status == shared::TorrentStatus::Error }) .count() }) }; let set_filter = move |f: crate::store::FilterStatus| { store.filter.set(f); }; let is_active = move |f: crate::store::FilterStatus| store.filter.get() == f; let username = move || { store.user.get().unwrap_or_else(|| "User".to_string()) }; let first_letter = move || { username().chars().next().unwrap_or('?').to_uppercase().to_string() }; let on_push_toggle = move |checked: bool| { spawn_local(async move { if checked { crate::store::subscribe_to_push_notifications().await; } else { crate::store::unsubscribe_from_push_notifications().await; } if let Ok(enabled) = crate::store::is_push_subscribed().await { store.push_enabled.set(enabled); } }); }; view! {
"VibeTorrent" "v3.0.0"
"Filtreler"
// Push Notification Toggle
"Bildirimler" "Web Push"
{first_letter}
{username}
"Yönetici"
} } #[component] fn SidebarItem( active: Signal, on_click: impl Fn(web_sys::MouseEvent) + 'static + Send, #[prop(into)] icon: String, #[prop(into)] label: &'static str, count: Signal, ) -> impl IntoView { 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() }; view! { {label} {count} } }