feat(web): AP debug page to see remote objects

This commit is contained in:
əlemi 2024-04-21 19:37:20 +02:00
parent 624492bcfb
commit cff4c827ca
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 39 additions and 1 deletions

View file

@ -99,6 +99,8 @@ pub fn App() -> impl IntoView {
<Route path="/web/users/:id" view=move || view! { <UserPage tl=user_tl /> } /> <Route path="/web/users/:id" view=move || view! { <UserPage tl=user_tl /> } />
<Route path="/web/objects/:id" view=move || view! { <ObjectPage tl=context_tl /> } /> <Route path="/web/objects/:id" view=move || view! { <ObjectPage tl=context_tl /> } />
<Route path="/web/debug" view=DebugPage />
<Route path="/" view=move || view! { <Redirect path="/web" /> } /> <Route path="/" view=move || view! { <Redirect path="/web" /> } />
</Routes> </Routes>
</main> </main>

View file

@ -10,7 +10,7 @@ pub fn Navigator() -> impl IntoView {
<a href="/web/home"><input class="w-100" type="submit" class:hidden=move || !auth.present() value="home timeline" /></a> <a href="/web/home"><input class="w-100" type="submit" class:hidden=move || !auth.present() value="home timeline" /></a>
<a href="/web/server"><input class="w-100" type="submit" value="server timeline" /></a> <a href="/web/server"><input class="w-100" type="submit" value="server timeline" /></a>
<a href="/web/about"><input class="w-100" type="submit" value="about" /></a> <a href="/web/about"><input class="w-100" type="submit" value="about" /></a>
<a href="/web/config"><input class="w-100" type="submit" value="config" class:hidden=move|| !auth.present() /></a> <a href="/web/debug"><input class="w-100" type="submit" value="debug" class:hidden=move|| !auth.present() /></a>
} }
} }

View file

@ -196,3 +196,39 @@ pub fn TimelinePage(name: &'static str, tl: Timeline) -> impl IntoView {
</div> </div>
} }
} }
#[component]
pub fn DebugPage() -> impl IntoView {
let url_ref: NodeRef<html::Input> = create_node_ref();
let (object, set_object) = create_signal(serde_json::Value::String(
"use this view to fetch remote AP objects and inspect their content".into())
);
let auth = use_context::<Auth>().expect("missing auth context");
view! {
<div>
<Breadcrumb back=true>debug</Breadcrumb>
<div class="mt-1" >
<table class="align w-100" >
<tr>
<td><input class="w-100" type="text" node_ref=url_ref placeholder="AP id" /></td>
<td>
<input type="submit" class="w-100" value="fetch" on:click=move |_| {
let fetch_url = url_ref.get().map(|x| x.value()).unwrap_or("".into());
let url = format!("{URL_BASE}/dbg?id={fetch_url}");
spawn_local(async move {
match Http::fetch::<serde_json::Value>(&url, auth).await {
Ok(x) => set_object.set(x),
Err(e) => set_object.set(serde_json::Value::String(e.to_string())),
}
});
} />
</td>
</tr>
</table>
</div>
<pre class="ma-1" >
{move || serde_json::to_string_pretty(&object.get()).unwrap_or("unserializable".to_string())}
</pre>
</div>
}
}