From c19cc19a907d1e3b103009d9428c4d6f018ffb70 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 23 May 2024 01:26:38 +0200 Subject: [PATCH] fix(web): update on cached toggled, tweak strings --- web/src/page/debug.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/web/src/page/debug.rs b/web/src/page/debug.rs index a3de8779..afde17a6 100644 --- a/web/src/page/debug.rs +++ b/web/src/page/debug.rs @@ -5,28 +5,29 @@ use crate::prelude::*; #[component] pub fn DebugPage() -> impl IntoView { let query_params = use_query_map(); - let query = move || { - query_params.with(|params| params.get("q").cloned().unwrap_or_default()) - }; let cached_ref: NodeRef = create_node_ref(); let auth = use_context::().expect("missing auth context"); + let (cached, set_cached) = create_signal(false); let (plain, set_plain) = create_signal(false); let (text, set_text) = create_signal("".to_string()); let navigate = use_navigate(); + let cached_query = move || ( + query_params.with(|params| params.get("q").cloned().unwrap_or_default()), + cached.get(), + ); let object = create_local_resource( - query, - move |q| async move { - set_text.set(q.clone()); - if q.is_empty() { return serde_json::Value::Null }; - let cached = cached_ref.get().map(|x| x.checked()).unwrap_or_default(); + cached_query, + move |(query, cached)| async move { + set_text.set(query.clone()); + if query.is_empty() { return serde_json::Value::Null }; if cached { - match CACHE.get(&q) { + match CACHE.get(&query) { Some(x) => (*x).clone(), None => serde_json::Value::Null, } } else { - debug_fetch(&format!("{URL_BASE}/proxy?id={q}"), auth).await + debug_fetch(&format!("{URL_BASE}/proxy?id={query}"), auth).await } } ); @@ -60,7 +61,7 @@ pub fn DebugPage() -> impl IntoView { /> - + @@ -75,7 +76,7 @@ pub fn DebugPage() -> impl IntoView {

" plain :: " - external + external " :: " serde_json::Value { #[component] fn DocumentNode(obj: serde_json::Value, #[prop(optional)] depth: usize) -> impl IntoView { let prefix = " ".repeat(depth); + let newline_replace = format!("\n{prefix} "); match obj { serde_json::Value::Null => view! { null }.into_view(), serde_json::Value::Bool(x) => view! { {x} }.into_view(), @@ -117,7 +119,7 @@ fn DocumentNode(obj: serde_json::Value, #[prop(optional)] depth: usize) -> impl }.into_view() } else { view! { - "\""{s}"\"" + "\""{s.replace("
", "
\n").replace('\n', &newline_replace)}
"\"" }.into_view() } },