use apb::{Actor, Base, Collection, Object}; use leptos::*; use leptos_router::*; use crate::prelude::*; #[component] pub fn AboutPage() -> impl IntoView { view! {
about

μpub" is a micro social network powered by "ActivityPub

} } #[component] pub fn UserPage() -> impl IntoView { let params = use_params_map(); let auth = use_context::().expect("missing auth context"); let actor = create_local_resource(move || params.get().get("id").cloned().unwrap_or_default(), move |id| { async move { match CACHE.get(&Uri::full("users", &id)) { Some(x) => Some(x.clone()), None => { let user : serde_json::Value = Http::fetch(&Uri::api("users", &id), auth).await.ok()?; CACHE.put(Uri::full("users", &id), user.clone()); Some(user) }, } } }); view! {
users::view
{move || match actor.get() { None => view! {

loading...

}.into_view(), Some(None) => view! {

error loading

}.into_view(), Some(Some(x)) => view! {

{ dissolve::strip_html_tags(x.summary().unwrap_or("")) .into_iter() .map(|x| view! {

{x}

}) .collect_view() }

  • type" "{x.actor_type().unwrap_or(apb::ActorType::Person).as_ref().to_string()}
  • following" "{x.following().get().map(|x| x.total_items().unwrap_or(0))}
  • followers" "{x.followers().get().map(|x| x.total_items().unwrap_or(0))}
  • created" "{x.published().map(|x| x.to_rfc3339())}

}.into_view(), }}
} } #[component] pub fn ObjectPage() -> impl IntoView { let params = use_params_map(); let auth = use_context::().expect("missing auth context"); let object = create_local_resource(move || params.get().get("id").cloned().unwrap_or_default(), move |oid| { async move { match CACHE.get(&Uri::full("objects", &oid)) { Some(x) => Some(x.clone()), None => { let obj = Http::fetch::(&Uri::api("objects", &oid), auth).await.ok()?; CACHE.put(Uri::full("objects", &oid), obj.clone()); Some(obj) } } } }); view! {
objects::view
{move || match object.get() { Some(Some(o)) => view!{ }.into_view(), Some(None) => view! {

loading failed

}.into_view(), None => view! {

loading ...

}.into_view(), }} } } #[component] pub fn TimelinePage(name: &'static str, tl: Timeline) -> impl IntoView { let auth = use_context::().expect("missing auth context"); view! { } }