mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-22 13:01:08 +00:00
still crashing
This commit is contained in:
parent
ee34c98b52
commit
e479c149a2
7 changed files with 14 additions and 95 deletions
|
@ -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<SiteView> {
|
||||
use_context::<Resource<SiteView>>().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<T> {
|
||||
fn with_default<O>(&self, f: impl FnOnce(&T) -> O) -> O;
|
||||
}
|
||||
|
||||
impl<T: Default + Send + Sync> DefaultResource<T> for Resource<T> {
|
||||
fn with_default<O>(&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! {
|
||||
<!DOCTYPE html>
|
||||
|
@ -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! {
|
||||
<Html attr:data-theme=darkmode.theme {..} class="h-full" />
|
||||
<Body {..} class="h-full max-sm:flex max-sm:flex-col" />
|
||||
<Html />
|
||||
<Body />
|
||||
<>
|
||||
<Stylesheet id="ibis" href="/pkg/ibis.css" />
|
||||
<Stylesheet id="katex" href="/katex.min.css" />
|
||||
<Router>
|
||||
<Nav />
|
||||
<main class="p-4 md:ml-64">
|
||||
<Routes fallback=|| "Page not found.".into_view()>
|
||||
<Route path=path!("/") view=Notifications />
|
||||
</Routes>
|
||||
</main>
|
||||
</Router>
|
||||
<Transition>
|
||||
<Show when=move || {
|
||||
use_context::<Resource<SiteView>>()
|
||||
.unwrap()
|
||||
.get_untracked()
|
||||
.unwrap_or_default()
|
||||
.my_profile
|
||||
.is_some()
|
||||
}>test</Show>
|
||||
</Transition>
|
||||
</>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
pub mod nav;
|
|
@ -1,31 +0,0 @@
|
|||
use crate::frontend::{api::CLIENT, app::is_logged_in};
|
||||
use leptos::{component, prelude::*, view, IntoView};
|
||||
use leptos_router::components::A;
|
||||
|
||||
#[component]
|
||||
pub fn Nav() -> impl IntoView {
|
||||
let notification_count = Resource::new(
|
||||
|| (),
|
||||
move |_| async move { CLIENT.notifications_count().await.unwrap_or_default() },
|
||||
);
|
||||
|
||||
view! {
|
||||
<nav>
|
||||
<Transition>
|
||||
<Show when=is_logged_in>
|
||||
<li>
|
||||
<A href="/article/create">"Create Article"</A>
|
||||
</li>
|
||||
<li>
|
||||
<A href="/notifications">
|
||||
"Notifications "
|
||||
<span class="indicator-item indicator-end badge badge-neutral">
|
||||
{move || notification_count.get()}
|
||||
</span>
|
||||
</A>
|
||||
</li>
|
||||
</Show>
|
||||
</Transition>
|
||||
</nav>
|
||||
}
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
pub fn render_markdown(text: &str) -> String {
|
||||
text.to_string()
|
||||
}
|
|
@ -1,9 +1,6 @@
|
|||
pub mod api;
|
||||
pub mod app;
|
||||
mod components;
|
||||
pub mod error;
|
||||
pub mod markdown;
|
||||
pub mod pages;
|
||||
|
||||
#[cfg(feature = "hydrate")]
|
||||
#[wasm_bindgen::prelude::wasm_bindgen]
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
pub(crate) mod notifications;
|
|
@ -1,6 +0,0 @@
|
|||
use leptos::prelude::*;
|
||||
|
||||
#[component]
|
||||
pub fn Notifications() -> impl IntoView {
|
||||
view! {}
|
||||
}
|
Loading…
Reference in a new issue