From 59ebee71a83a16475aba9ddc764146259f06d4c1 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 18 Apr 2024 05:00:44 +0200 Subject: [PATCH] feat(web): individual views will request fetches --- web/src/lib.rs | 4 ++-- web/src/page.rs | 6 +++--- web/src/timeline.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/web/src/lib.rs b/web/src/lib.rs index ecf1d76d..f3ad655e 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -126,7 +126,7 @@ impl Uri { /// - https://other.domain.net/unexpected/path/root /// - +other.domain.net@users@root /// - root - pub fn api(kind: &str, url: &str) -> String { - format!("{URL_BASE}/{kind}/{}", Self::short(url)) + pub fn api(kind: &str, url: &str, fetch: bool) -> String { + format!("{URL_BASE}/{kind}/{}{}", Self::short(url), if fetch { "?fetch=true" } else { "" }) } } diff --git a/web/src/page.rs b/web/src/page.rs index dc01fcfa..f3dff908 100644 --- a/web/src/page.rs +++ b/web/src/page.rs @@ -41,7 +41,7 @@ pub fn UserPage() -> impl IntoView { match CACHE.get(&Uri::full("users", &id)) { Some(x) => Some(x.clone()), None => { - let user : serde_json::Value = Http::fetch(&Uri::api("users", &id), auth).await.ok()?; + let user : serde_json::Value = Http::fetch(&Uri::api("users", &id, true), auth).await.ok()?; CACHE.put(Uri::full("users", &id), user.clone()); Some(user) }, @@ -116,7 +116,7 @@ pub fn UserPage() -> impl IntoView { } - + }.into_view() }, }} @@ -134,7 +134,7 @@ pub fn ObjectPage() -> impl IntoView { match CACHE.get(&Uri::full("objects", &oid)) { Some(x) => Some(x.clone()), None => { - let obj = Http::fetch::(&Uri::api("objects", &oid), auth).await.ok()?; + let obj = Http::fetch::(&Uri::api("objects", &oid, true), auth).await.ok()?; CACHE.put(Uri::full("objects", &oid), obj.clone()); Some(obj) } diff --git a/web/src/timeline.rs b/web/src/timeline.rs index 2f72703c..badc59b2 100644 --- a/web/src/timeline.rs +++ b/web/src/timeline.rs @@ -126,7 +126,7 @@ async fn process_activities( } async fn fetch_and_update(kind: &'static str, id: String, auth: Signal>) { - match Http::fetch(&Uri::api(kind, &id), auth).await { + match Http::fetch(&Uri::api(kind, &id, false), auth).await { Ok(data) => CACHE.put(id, data), Err(e) => console_warn(&format!("could not fetch '{id}': {e}")), }