mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-25 19:01:09 +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::{
|
use crate::common::SiteView;
|
||||||
common::SiteView,
|
use crate::frontend::api::CLIENT;
|
||||||
frontend::{api::CLIENT, components::nav::Nav, pages::notifications::Notifications},
|
|
||||||
};
|
|
||||||
use leptos::prelude::*;
|
use leptos::prelude::*;
|
||||||
use leptos_meta::{provide_meta_context, *};
|
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 {
|
pub fn shell(options: LeptosOptions) -> impl IntoView {
|
||||||
view! {
|
view! {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
@ -60,24 +25,23 @@ pub fn shell(options: LeptosOptions) -> impl IntoView {
|
||||||
pub fn App() -> impl IntoView {
|
pub fn App() -> impl IntoView {
|
||||||
provide_meta_context();
|
provide_meta_context();
|
||||||
|
|
||||||
// TODO: should Resource::new() but then things break
|
|
||||||
let site_resource = Resource::new(|| (), |_| async move { CLIENT.site().await.unwrap() });
|
let site_resource = Resource::new(|| (), |_| async move { CLIENT.site().await.unwrap() });
|
||||||
provide_context(site_resource);
|
provide_context(site_resource);
|
||||||
|
|
||||||
view! {
|
view! {
|
||||||
<Html attr:data-theme=darkmode.theme {..} class="h-full" />
|
<Html />
|
||||||
<Body {..} class="h-full max-sm:flex max-sm:flex-col" />
|
<Body />
|
||||||
<>
|
<>
|
||||||
<Stylesheet id="ibis" href="/pkg/ibis.css" />
|
<Transition>
|
||||||
<Stylesheet id="katex" href="/katex.min.css" />
|
<Show when=move || {
|
||||||
<Router>
|
use_context::<Resource<SiteView>>()
|
||||||
<Nav />
|
.unwrap()
|
||||||
<main class="p-4 md:ml-64">
|
.get_untracked()
|
||||||
<Routes fallback=|| "Page not found.".into_view()>
|
.unwrap_or_default()
|
||||||
<Route path=path!("/") view=Notifications />
|
.my_profile
|
||||||
</Routes>
|
.is_some()
|
||||||
</main>
|
}>test</Show>
|
||||||
</Router>
|
</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 api;
|
||||||
pub mod app;
|
pub mod app;
|
||||||
mod components;
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod markdown;
|
|
||||||
pub mod pages;
|
|
||||||
|
|
||||||
#[cfg(feature = "hydrate")]
|
#[cfg(feature = "hydrate")]
|
||||||
#[wasm_bindgen::prelude::wasm_bindgen]
|
#[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