diff --git a/src/frontend/app.rs b/src/frontend/app.rs index 466022d..57b8f90 100644 --- a/src/frontend/app.rs +++ b/src/frontend/app.rs @@ -1,43 +1,8 @@ -use crate::{ - common::SiteView, - frontend::{api::CLIENT, components::nav::Nav, pages::notifications::Notifications}, -}; +use crate::common::SiteView; +use crate::frontend::api::CLIENT; use leptos::prelude::*; use leptos_meta::{provide_meta_context, *}; -use leptos_router::{ - components::{Route, Router, Routes}, - path, -}; -pub fn site() -> Resource { - use_context::>().unwrap() -} - -pub fn is_logged_in() -> bool { - site().with_default(|site| site.my_profile.is_some()) -} -pub fn is_admin() -> bool { - site().with_default(|site| { - site.my_profile - .as_ref() - .map(|p| p.local_user.admin) - .unwrap_or(false) - }) -} - -// TODO: can probably get rid of this -pub trait DefaultResource { - fn with_default(&self, f: impl FnOnce(&T) -> O) -> O; -} - -impl DefaultResource for Resource { - fn with_default(&self, f: impl FnOnce(&T) -> O) -> O { - self.with(|x| match x { - Some(x) => f(x), - None => f(&T::default()), - }) - } -} pub fn shell(options: LeptosOptions) -> impl IntoView { view! { @@ -60,24 +25,23 @@ pub fn shell(options: LeptosOptions) -> impl IntoView { pub fn App() -> impl IntoView { provide_meta_context(); - // TODO: should Resource::new() but then things break let site_resource = Resource::new(|| (), |_| async move { CLIENT.site().await.unwrap() }); provide_context(site_resource); view! { - - + + <> - - - -