use std::sync::Arc; use leptos::*; use crate::prelude::*; #[component] pub fn DebugPage() -> impl IntoView { let (object, set_object) = create_signal(Arc::new(serde_json::Value::String( "use this view to fetch remote AP objects and inspect their content".into()) )); let cached_ref: NodeRef = create_node_ref(); let auth = use_context::().expect("missing auth context"); let (query, set_query) = create_signal("".to_string()); view! {
config :: devtools
set_object.set(x), None => set_object.set(Arc::new(serde_json::Value::String("not in cache!".into()))), } } else { let url = format!("{URL_BASE}/dbg?id={fetch_url}"); spawn_local(async move { set_object.set(Arc::new(debug_fetch(&url, auth).await)) }); } } >
obj " " usr
				{move || serde_json::to_string_pretty(object.get().as_ref()).unwrap_or("unserializable".to_string())}
			
} } // this is a rather weird way to fetch but i want to see the bare error text if it fails! async fn debug_fetch(url: &str, token: Auth) -> serde_json::Value { match Http::request::<()>(reqwest::Method::GET, url, None, token).await { Err(e) => serde_json::Value::String(format!("[!] failed sending request: {e}")), Ok(res) => match res.text().await { Err(e) => serde_json::Value::String(format!("[!] invalid response body: {e}")), Ok(x) => match serde_json::from_str(&x) { Err(_) => serde_json::Value::String(x), Ok(v) => v, }, } } }