feat(web): error pages have direct link to debug

This commit is contained in:
əlemi 2024-04-22 02:48:33 +02:00
parent 5a8887c690
commit 870e46ba31
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -34,9 +34,18 @@ pub fn ConfigPage() -> impl IntoView {
pub fn UserPage(tl: Timeline) -> impl IntoView { pub fn UserPage(tl: Timeline) -> impl IntoView {
let params = use_params_map(); let params = use_params_map();
let auth = use_context::<Auth>().expect("missing auth context"); let auth = use_context::<Auth>().expect("missing auth context");
let id = params.get().get("id").cloned().unwrap_or_default(); let id = params.get()
let _id = id.clone(); // wtf triple clone??? TODO!! .get("id")
let actor = create_local_resource(move || _id.clone(), move |id| { .cloned()
.unwrap_or_default();
let mut uid = id
.replace("/web/objects/", "")
.replacen('+', "https://", 1)
.replace('@', "/");
if !uid.starts_with("http") {
uid = format!("{URL_BASE}/web/objects/{uid}");
}
let actor = create_local_resource(move || params.get().get("id").cloned().unwrap_or_default(), move |id| {
async move { async move {
match CACHE.get(&Uri::full(FetchKind::User, &id)) { match CACHE.get(&Uri::full(FetchKind::User, &id)) {
Some(x) => Some(x.clone()), Some(x) => Some(x.clone()),
@ -52,9 +61,13 @@ pub fn UserPage(tl: Timeline) -> impl IntoView {
<div> <div>
<Breadcrumb back=true >users::view</Breadcrumb> <Breadcrumb back=true >users::view</Breadcrumb>
<div> <div>
{move || match actor.get() { {move || {
None => view! { <p>loading...</p> }.into_view(), let uid = uid.clone();
Some(None) => view! { <p><code>error loading</code></p> }.into_view(), match actor.get() {
None => view! { <p class="center">loading...</p> }.into_view(),
Some(None) => {
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(object)) => { Some(Some(object)) => {
let uid = object.id().unwrap_or_default().to_string(); let uid = object.id().unwrap_or_default().to_string();
let avatar_url = object.icon().get().map(|x| x.url().id().unwrap_or_default()).unwrap_or_default(); let avatar_url = object.icon().get().map(|x| x.url().id().unwrap_or_default()).unwrap_or_default();
@ -124,6 +137,7 @@ pub fn UserPage(tl: Timeline) -> impl IntoView {
<TimelineFeed tl=tl /> <TimelineFeed tl=tl />
}.into_view() }.into_view()
}, },
}
}} }}
</div> </div>
</div> </div>
@ -134,6 +148,15 @@ pub fn UserPage(tl: Timeline) -> impl IntoView {
pub fn ObjectPage(tl: Timeline) -> impl IntoView { pub fn ObjectPage(tl: Timeline) -> impl IntoView {
let params = use_params_map(); let params = use_params_map();
let auth = use_context::<Auth>().expect("missing auth context"); let auth = use_context::<Auth>().expect("missing auth context");
let mut uid = params.get().get("id")
.cloned()
.unwrap_or_default()
.replace("/web/objects/", "")
.replacen('+', "https://", 1)
.replace('@', "/");
if !uid.starts_with("http") {
uid = format!("{URL_BASE}/web/objects/{uid}");
}
let object = create_local_resource(move || params.get().get("id").cloned().unwrap_or_default(), move |oid| { let object = create_local_resource(move || params.get().get("id").cloned().unwrap_or_default(), move |oid| {
async move { async move {
match CACHE.get(&Uri::full(FetchKind::Object, &oid)) { match CACHE.get(&Uri::full(FetchKind::Object, &oid)) {
@ -151,8 +174,11 @@ pub fn ObjectPage(tl: Timeline) -> impl IntoView {
<Breadcrumb back=true >objects::view</Breadcrumb> <Breadcrumb back=true >objects::view</Breadcrumb>
<div class="ma-2" > <div class="ma-2" >
{move || match object.get() { {move || match object.get() {
None => view! { <p> loading ... </p> }.into_view(), None => view! { <p class="center"> loading ... </p> }.into_view(),
Some(None) => view! { <p><code>loading failed</code></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)) => { Some(Some(o)) => {
let object = o.clone(); let object = o.clone();
let tl_url = format!("{}/page", Uri::api(FetchKind::Context, &o.context().id().unwrap_or_default(), false)); let tl_url = format!("{}/page", Uri::api(FetchKind::Context, &o.context().id().unwrap_or_default(), false));