//! The signed-in shell: left sidebar (folders + manage tabs) and the topbar. use leptos::prelude::*; use wasm_bindgen_futures::spawn_local; use crate::api::{self, Me}; use crate::components::icon::Icon; use crate::components::logo::Logo; use crate::components::toast::{ToastView, provide_toast}; use crate::icons::IconName; use crate::router::{Location, navigate}; use crate::views::admin::{SettingsView, UsersView}; use crate::views::browser::{Browser, effective_root}; use crate::views::shares::SharesView; /// Whether the signed-in user has admin rights. fn is_admin_of(me: &Option) -> bool { me.as_ref() .and_then(|m| m.user.as_ref()) .is_some_and(|u| u.is_admin) } /// Which section of the shell is showing. `Files` is the browser; the rest are /// the "manage" sections. The file location lives in the URL hash, the manage /// panel is in-memory state. #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub enum Panel { Files, Shares, Users, Settings, } #[component] pub fn ShellView( me: ReadSignal>, set_me: WriteSignal>, set_phase: WriteSignal, loc: ReadSignal, theme: ReadSignal, set_theme: WriteSignal, ) -> impl IntoView { let toast = provide_toast(); let (panel, set_panel) = signal(Panel::Files); // True while the off-canvas sidebar is open (narrow screens only). let (nav_open, set_nav_open) = signal(false); let on_logout = move |_| { spawn_local(async move { let _ = api::logout().await; set_me.set(None); set_phase.set(crate::app::AuthPhase::Login); }); }; // Select a manage section; on narrow screens the sidebar closes. let open_panel = Callback::new(move |p: Panel| { set_panel.set(p); set_nav_open.set(false); }); view! {
"filebrowser-ng"
{move || { let Some(u) = me.get().and_then(|m| m.user) else { return { view! {}.into_any() }; }; view! { {u.name.clone()} } .into_view() .into_any() }}
{move || { if nav_open.get() { view! { } .into_view() .into_any() } else { view! {}.into_any() } }}
{move || { let admin = is_admin_of(&me.get()); match panel.get() { Panel::Files => view! { } .into_view() .into_any(), Panel::Shares => view! { } .into_view() .into_any(), Panel::Users if admin => { view! { }.into_view().into_any() } Panel::Settings if admin => { view! { }.into_view().into_any() } // Not an admin anymore (e.g. permissions changed): // fall back to the files view. _ => view! { } .into_view() .into_any(), } }}
} }