From 268265e34a9b5c8755e83c739b7a45236ad47fa3 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 15 Apr 2024 05:00:23 +0200 Subject: [PATCH] feat: routing under /web, scroll only tl --- web/index.html | 9 ++++++ web/src/lib.rs | 74 ++++++++++++++++++++++++++----------------------- web/src/main.rs | 7 +++-- 3 files changed, 52 insertions(+), 38 deletions(-) diff --git a/web/index.html b/web/index.html index ca6c0c4..ac604af 100644 --- a/web/index.html +++ b/web/index.html @@ -20,6 +20,15 @@ max-height: 2em; border-radius: 50%; } + div.boxscroll { + max-height: calc(100vh - 8rem); + overflow-y: scroll; + } + @media screen and (max-width: 786px) { + div.boxscroll { + max-height: 100%; + } + } table.align { line-height: 1rem; } diff --git a/web/src/lib.rs b/web/src/lib.rs index 60e76de..12297be 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -3,9 +3,10 @@ use std::sync::Arc; use apb::{target::Addressed, Activity, ActivityMut, Actor, Base, Collection, Object, ObjectMut}; use dashmap::DashMap; use leptos::{leptos_dom::logging::console_log, *}; -use leptos_router::use_params_map; +use leptos_router::*; -pub const BASE_URL: &str = "https://feditest.alemi.dev"; +pub const URL_BASE: &str = "https://feditest.alemi.dev"; +pub const URL_PREFIX: &str = "/web"; #[derive(Debug, serde::Serialize)] struct LoginForm { @@ -23,7 +24,7 @@ pub fn LoginBox( view! {
- "Hello "test + "Hello "test @@ -38,7 +39,7 @@ pub fn LoginBox( let password = password_ref.get().map(|x| x.value()).unwrap_or("".into()); spawn_local(async move { let auth = reqwest::Client::new() - .post(format!("{BASE_URL}/auth")) + .post(format!("{URL_BASE}/auth")) .json(&LoginForm { email, password }) .send() .await.unwrap() @@ -66,7 +67,7 @@ pub fn PostBox(token: Signal>) -> impl IntoView { let summary = summary_ref.get().map(|x| x.value()); let content = content_ref.get().map(|x| x.value()).unwrap_or("".into()); reqwest::Client::new() - .post(format!("{BASE_URL}/users/test/outbox")) + .post(format!("{URL_BASE}/users/test/outbox")) .header("Authorization", format!("Bearer {}", token.get().unwrap_or_default())) .json( &serde_json::Value::Object(serde_json::Map::default()) @@ -74,7 +75,7 @@ pub fn PostBox(token: Signal>) -> impl IntoView { .set_summary(summary.as_deref()) .set_content(Some(&content)) .set_to(apb::Node::links(vec![apb::target::PUBLIC.to_string()])) - .set_cc(apb::Node::links(vec![format!("{BASE_URL}/users/test/followers")])) + .set_cc(apb::Node::links(vec![format!("{URL_BASE}/users/test/followers")])) ) .send() .await.unwrap() @@ -114,6 +115,7 @@ pub fn ActorBanner(object: serde_json::Value) -> impl IntoView {
{id}
}, serde_json::Value::Object(_) => { + let uid = object.id().unwrap_or_default().split('/').last().unwrap_or_default().to_string(); let avatar_url = object.icon().get().map(|x| x.url().id().unwrap_or_default()).unwrap_or_default(); let display_name = object.name().unwrap_or_default().to_string(); let username = object.preferred_username().unwrap_or_default().to_string(); @@ -126,7 +128,7 @@ pub fn ActorBanner(object: serde_json::Value) -> impl IntoView { {display_name} - {username}@{domain} + {username}@{domain}
@@ -143,7 +145,7 @@ pub fn Actor() -> impl IntoView { let params = use_params_map(); let actor = create_local_resource(move || params.get().get("id").cloned().unwrap_or_default(), |uid| { async move { - reqwest::get(format!("{BASE_URL}/users/{uid}")) + reqwest::get(format!("{URL_BASE}/users/{uid}")) .await .unwrap() .json::() @@ -228,7 +230,7 @@ struct OmgReqwestErrorIsNotClonable(String); pub fn Timeline( token: Signal>, ) -> impl IntoView { - let (timeline, set_timeline) = create_signal(format!("{BASE_URL}/inbox/page")); + let (timeline, set_timeline) = create_signal(format!("{URL_BASE}/inbox/page")); let users : Arc> = Arc::new(DashMap::new()); let _users = users.clone(); // TODO i think there is syntactic sugar i forgot? let items = create_local_resource(move || timeline.get(), move |feed_url| { @@ -238,32 +240,34 @@ pub fn Timeline( view! {
- {format!("{:?}", err.get())}

} > - {move || items.with(|x| match x { - None => Ok(view! {

loading...

}.into_view()), - Some(data) => match data { - Err(e) => Err(OmgReqwestErrorIsNotClonable(e.to_string())), - Ok(values) => Ok( - values - .iter() - .map(|object| { - let actor = object.actor().extract().unwrap_or_else(|| - serde_json::Value::String(object.actor().id().unwrap_or_default()) - ); - view! { -
- - -
-
- } - }) - .collect::>() - .into_view() - ), - } - })} -
+
+ {format!("{:?}", err.get())}

} > + {move || items.with(|x| match x { + None => Ok(view! {

loading...

}.into_view()), + Some(data) => match data { + Err(e) => Err(OmgReqwestErrorIsNotClonable(e.to_string())), + Ok(values) => Ok( + values + .iter() + .map(|object| { + let actor = object.actor().extract().unwrap_or_else(|| + serde_json::Value::String(object.actor().id().unwrap_or_default()) + ); + view! { +
+ + +
+
+ } + }) + .collect::>() + .into_view() + ), + } + })} +
+
} } diff --git a/web/src/main.rs b/web/src/main.rs index 1b98e8a..bef9813 100644 --- a/web/src/main.rs +++ b/web/src/main.rs @@ -6,6 +6,7 @@ use upub_web::{ Actor, LoginBox, PostBox, Timeline }; + fn main() { _ = console_log::init_with_level(log::Level::Debug); console_error_panic_hook::set_once(); @@ -15,7 +16,7 @@ fn main() {