From 99d613a1e8557362a0a2bc6395b987aa9b082c00 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 11 May 2024 21:49:55 +0200 Subject: [PATCH] fix(web): more consistent object rendering --- web/src/components/activity.rs | 38 ++++++++++++++- web/src/components/timeline.rs | 84 ++++++---------------------------- 2 files changed, 50 insertions(+), 72 deletions(-) diff --git a/web/src/components/activity.rs b/web/src/components/activity.rs index a85cfad2..1994d4ad 100644 --- a/web/src/components/activity.rs +++ b/web/src/components/activity.rs @@ -1,7 +1,7 @@ use leptos::*; use crate::prelude::*; -use apb::{target::Addressed, Activity, Object}; +use apb::{target::Addressed, Base, Activity, Object}; #[component] @@ -31,3 +31,39 @@ pub fn ActivityLine(activity: crate::Object) -> impl IntoView { } } + +#[component] +pub fn Item(item: crate::Object) -> impl IntoView { + let id = item.id().unwrap_or_default().to_string(); + match item.object_type() { + // special case for placeholder activities + Some(apb::ObjectType::Note) | Some(apb::ObjectType::Document(_)) => + view! { }.into_view(), + // everything else + Some(apb::ObjectType::Activity(t)) => { + let object_id = item.object().id().unwrap_or_default(); + let object = match t { + apb::ActivityType::Create | apb::ActivityType::Announce => + CACHE.get(&object_id).map(|obj| { + view! { } + }.into_view()), + apb::ActivityType::Follow => + CACHE.get(&object_id).map(|obj| { + view! { +
+ + +
+ } + }.into_view()), + _ => None, + }; + view! { + + {object} + }.into_view() + }, + // should never happen + _ => view! {

type not implemented

}.into_view(), + } +} diff --git a/web/src/components/timeline.rs b/web/src/components/timeline.rs index f38271de..0432875a 100644 --- a/web/src/components/timeline.rs +++ b/web/src/components/timeline.rs @@ -92,44 +92,15 @@ pub fn TimelineRepliesRecursive(tl: Timeline, root: String) -> impl IntoView { { - let oid = object.object().id().unwrap_or_default().to_string(); - if let Some(note) = CACHE.get(&oid) { - view! { -
- - -
- -
- - } - } else { - view! { -
- -
- } - } - }, - Some(apb::ObjectType::Activity(_)) => view! { -
- + children=move |obj: crate::Object| { + let oid = obj.id().unwrap_or_default().to_string(); + view! { +
+ +
+
- }, - _ => { - let oid = object.id().unwrap_or_default().to_string(); - view! { -
- -
- -
- - } - }, + } } / > @@ -168,42 +139,13 @@ pub fn TimelineFeed(tl: Timeline) -> impl IntoView { key=|k| k.to_string() children=move |id: String| { match CACHE.get(&id) { - Some(item) => match item.object_type() { - // special case for placeholder activities - Some(apb::ObjectType::Note) => view! { - -
- }.into_view(), - // everything else - Some(apb::ObjectType::Activity(t)) => { - let object_id = item.object().id().unwrap_or_default(); - let object = match t { - apb::ActivityType::Create | apb::ActivityType::Announce => - CACHE.get(&object_id).map(|obj| { - view! { } - }.into_view()), - apb::ActivityType::Follow => - CACHE.get(&object_id).map(|obj| { - view! { -
- - -
- } - }.into_view()), - _ => None, - }; - view! { - - {object} -
- }.into_view() - }, - // should never happen - _ => view! {

type not implemented


}.into_view(), - }, + Some(i) => view! { + +
+ }.into_view(), None => view! {

{id}" "[go]

+
}.into_view(), } }