2024-05-13 19:13:40 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
use leptos::*;
|
|
|
|
use leptos_router::*;
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
|
|
|
use apb::{Base, Object};
|
|
|
|
|
|
|
|
#[component]
|
|
|
|
pub fn ObjectPage(tl: Timeline) -> impl IntoView {
|
|
|
|
let params = use_params_map();
|
|
|
|
let auth = use_context::<Auth>().expect("missing auth context");
|
2024-05-20 06:59:16 +02:00
|
|
|
let id = params.get().get("id").cloned().unwrap_or_default();
|
|
|
|
let uid = uriproxy::uri(URL_BASE, uriproxy::UriClass::Object, &id);
|
2024-05-30 22:58:31 +02:00
|
|
|
let object = create_local_resource(
|
|
|
|
move || params.get().get("id").cloned().unwrap_or_default(),
|
|
|
|
move |oid| async move {
|
|
|
|
let tl_url = format!("{}/page", Uri::api(U::Context, &oid, false));
|
|
|
|
if !tl.next.get().starts_with(&tl_url) {
|
|
|
|
tl.reset(tl_url);
|
|
|
|
}
|
2024-05-20 06:25:47 +02:00
|
|
|
match CACHE.get(&Uri::full(U::Object, &oid)) {
|
2024-05-13 19:13:40 +02:00
|
|
|
Some(x) => Some(x.clone()),
|
|
|
|
None => {
|
2024-05-20 06:25:47 +02:00
|
|
|
let obj = Http::fetch::<serde_json::Value>(&Uri::api(U::Object, &oid, true), auth).await.ok()?;
|
2024-05-13 19:13:40 +02:00
|
|
|
let obj = Arc::new(obj);
|
|
|
|
if let Some(author) = obj.attributed_to().id() {
|
|
|
|
if let Ok(user) = Http::fetch::<serde_json::Value>(
|
2024-05-29 21:36:55 +02:00
|
|
|
&Uri::api(U::Actor, &author, true), auth
|
2024-05-13 19:13:40 +02:00
|
|
|
).await {
|
2024-05-29 21:36:55 +02:00
|
|
|
CACHE.put(Uri::full(U::Actor, &author), Arc::new(user));
|
2024-05-13 19:13:40 +02:00
|
|
|
}
|
|
|
|
}
|
2024-05-20 06:25:47 +02:00
|
|
|
CACHE.put(Uri::full(U::Object, &oid), obj.clone());
|
2024-05-13 19:13:40 +02:00
|
|
|
Some(obj)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-05-30 22:58:31 +02:00
|
|
|
);
|
2024-05-13 19:13:40 +02:00
|
|
|
view! {
|
|
|
|
<div>
|
|
|
|
<Breadcrumb back=true >
|
|
|
|
objects::view
|
|
|
|
<a
|
|
|
|
class="clean ml-1" href="#"
|
|
|
|
class:hidden=move || tl.is_empty()
|
|
|
|
on:click=move |_| {
|
|
|
|
tl.reset(tl.next.get().split('?').next().unwrap_or_default().to_string());
|
2024-05-27 16:50:42 +02:00
|
|
|
tl.more(auth);
|
2024-05-13 19:13:40 +02:00
|
|
|
}><span class="emoji">
|
|
|
|
"\u{1f5d8}"
|
|
|
|
</span></a>
|
|
|
|
</Breadcrumb>
|
|
|
|
<div class="ma-2" >
|
|
|
|
{move || match object.get() {
|
|
|
|
None => view! { <p class="center"> loading ... </p> }.into_view(),
|
|
|
|
Some(None) => {
|
|
|
|
let uid = uid.clone();
|
|
|
|
view! { <p class="center"><code>loading failed</code><sup><small><a class="clean" href={uid} target="_blank">"↗"</a></small></sup></p> }.into_view()
|
|
|
|
},
|
|
|
|
Some(Some(o)) => {
|
|
|
|
let object = o.clone();
|
|
|
|
view!{
|
|
|
|
<Object object=object />
|
|
|
|
<div class="ml-1 mr-1 mt-2">
|
|
|
|
<TimelineReplies tl=tl root=o.id().unwrap_or_default().to_string() />
|
|
|
|
</div>
|
|
|
|
}.into_view()
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|