1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-25 19:01:09 +00:00

still crashing

This commit is contained in:
Felix Ableitner 2024-11-20 15:53:34 +01:00
parent ee34c98b52
commit e479c149a2
7 changed files with 14 additions and 95 deletions

View file

@ -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>
</> </>
} }
} }

View file

@ -1 +0,0 @@
pub mod nav;

View file

@ -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>
}
}

View file

@ -1,3 +0,0 @@
pub fn render_markdown(text: &str) -> String {
text.to_string()
}

View file

@ -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]

View file

@ -1 +0,0 @@
pub(crate) mod notifications;

View file

@ -1,6 +0,0 @@
use leptos::prelude::*;
#[component]
pub fn Notifications() -> impl IntoView {
view! {}
}