feat(web): basic context view for posts

This commit is contained in:
əlemi 2024-04-19 06:59:34 +02:00
parent fc2a62239b
commit 6edda7236e
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 28 additions and 10 deletions

View file

@ -18,6 +18,7 @@ pub fn App() -> impl IntoView {
let home_tl = Timeline::new(format!("{URL_BASE}/users/{}/inbox/page", username.get().unwrap_or_default()));
let server_tl = Timeline::new(format!("{URL_BASE}/inbox/page"));
let user_tl = Timeline::new(format!("{URL_BASE}/users/{}/outbox/page", username.get().unwrap_or_default()));
let context_tl = Timeline::new(format!("{URL_BASE}/outbox/page"));
let screen_width = window().screen().map(|x| x.avail_width().unwrap_or_default()).unwrap_or_default();
@ -95,8 +96,8 @@ pub fn App() -> impl IntoView {
<Route path="/web/config" view=ConfigPage />
<Route path="/web/about" view=AboutPage />
<Route path="/web/objects/:id" view=ObjectPage />
<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="/" view=move || view! { <Redirect path="/web" /> } />
</Routes>

View file

@ -131,7 +131,7 @@ pub fn UserPage(tl: Timeline) -> impl IntoView {
}
#[component]
pub fn ObjectPage() -> impl IntoView {
pub fn ObjectPage(tl: Timeline) -> impl IntoView {
let params = use_params_map();
let auth = use_context::<Auth>().expect("missing auth context");
let object = create_local_resource(move || params.get().get("id").cloned().unwrap_or_default(), move |oid| {
@ -151,9 +151,20 @@ pub fn ObjectPage() -> impl IntoView {
<Breadcrumb back=true >objects::view</Breadcrumb>
<div class="ma-2" >
{move || match object.get() {
Some(Some(o)) => view!{ <Object object=o /> }.into_view(),
Some(None) => view! { <p><code>loading failed</code></p> }.into_view(),
None => view! { <p> loading ... </p> }.into_view(),
Some(None) => view! { <p><code>loading failed</code></p> }.into_view(),
Some(Some(o)) => {
let tl_url = format!("{}/page", Uri::api("context", &o.context().id().unwrap_or_default(), false));
if !tl.next.get().starts_with(&tl_url) {
tl.reset(tl_url);
}
view!{
<Object object=o.clone() />
<div class="ml-1 mr-1 mt-2">
<TimelineFeed tl=tl />
</div>
}.into_view()
},
}}
</div>
</div>

View file

@ -1,5 +1,6 @@
use std::collections::BTreeSet;
use apb::Base;
use leptos::*;
use crate::prelude::*;
@ -52,11 +53,16 @@ pub fn TimelineFeed(tl: Timeline) -> impl IntoView {
key=|k| k.to_string()
children=move |id: String| {
match CACHE.get(&id) {
Some(object) => {
view! {
<InlineActivity activity=object />
<hr/ >
}.into_view()
Some(object) => match object.base_type() {
Some(apb::BaseType::Object(apb::ObjectType::Activity(_))) => view! {
<InlineActivity activity=object />
<hr/ >
}.into_view(),
Some(apb::BaseType::Object(apb::ObjectType::Note)) => view! {
<Object object=object />
<hr/ >
}.into_view(),
_ => view! { <p><code>type not implemented</code></p><hr /> }.into_view(),
},
None => view! {
<p><code>{id}</code>" "[<a href={uri}>go</a>]</p>
@ -82,7 +88,7 @@ async fn process_activities(
activities: Vec<serde_json::Value>,
auth: Signal<Option<String>>,
) -> Vec<String> {
use apb::{Base, Activity, ActivityMut};
use apb::{Activity, ActivityMut};
let mut sub_tasks = Vec::new();
let mut gonna_fetch = BTreeSet::new();
let mut out = Vec::new();