forked from alemi/upub
fix(web): more consistent object rendering
This commit is contained in:
parent
a60b5774a1
commit
99d613a1e8
2 changed files with 50 additions and 72 deletions
|
@ -1,7 +1,7 @@
|
||||||
use leptos::*;
|
use leptos::*;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use apb::{target::Addressed, Activity, Object};
|
use apb::{target::Addressed, Base, Activity, Object};
|
||||||
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
|
@ -31,3 +31,39 @@ pub fn ActivityLine(activity: crate::Object) -> impl IntoView {
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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! { <Object object=item /> }.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! { <Object object=obj /> }
|
||||||
|
}.into_view()),
|
||||||
|
apb::ActivityType::Follow =>
|
||||||
|
CACHE.get(&object_id).map(|obj| {
|
||||||
|
view! {
|
||||||
|
<div class="ml-1">
|
||||||
|
<ActorBanner object=obj />
|
||||||
|
<FollowRequestButtons activity_id=id actor_id=object_id />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
}.into_view()),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
view! {
|
||||||
|
<ActivityLine activity=item />
|
||||||
|
{object}
|
||||||
|
}.into_view()
|
||||||
|
},
|
||||||
|
// should never happen
|
||||||
|
_ => view! { <p><code>type not implemented</code></p> }.into_view(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -92,44 +92,15 @@ pub fn TimelineRepliesRecursive(tl: Timeline, root: String) -> impl IntoView {
|
||||||
<For
|
<For
|
||||||
each=root_values
|
each=root_values
|
||||||
key=|k| k.id().unwrap_or_default().to_string()
|
key=|k| k.id().unwrap_or_default().to_string()
|
||||||
children=move |object: crate::Object| {
|
children=move |obj: crate::Object| {
|
||||||
match object.object_type() {
|
let oid = obj.id().unwrap_or_default().to_string();
|
||||||
Some(apb::ObjectType::Activity(apb::ActivityType::Create)) => {
|
view! {
|
||||||
let oid = object.object().id().unwrap_or_default().to_string();
|
<div class="context depth-r">
|
||||||
if let Some(note) = CACHE.get(&oid) {
|
<Item item=obj />
|
||||||
view! {
|
<div class="depth-r">
|
||||||
<div class="context depth-r">
|
<TimelineRepliesRecursive tl=tl root=oid />
|
||||||
<ActivityLine activity=object />
|
|
||||||
<Object object=note />
|
|
||||||
<div class="depth-r">
|
|
||||||
<TimelineRepliesRecursive tl=tl root=oid />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
view! {
|
|
||||||
<div class="context depth-r">
|
|
||||||
<ActivityLine activity=object />
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Some(apb::ObjectType::Activity(_)) => view! {
|
|
||||||
<div class="context depth-r">
|
|
||||||
<ActivityLine activity=object />
|
|
||||||
</div>
|
</div>
|
||||||
},
|
</div>
|
||||||
_ => {
|
|
||||||
let oid = object.id().unwrap_or_default().to_string();
|
|
||||||
view! {
|
|
||||||
<div class="context depth-r">
|
|
||||||
<Object object=object />
|
|
||||||
<div class="depth-r">
|
|
||||||
<TimelineRepliesRecursive tl=tl root=oid />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/ >
|
/ >
|
||||||
|
@ -168,42 +139,13 @@ pub fn TimelineFeed(tl: Timeline) -> impl IntoView {
|
||||||
key=|k| k.to_string()
|
key=|k| k.to_string()
|
||||||
children=move |id: String| {
|
children=move |id: String| {
|
||||||
match CACHE.get(&id) {
|
match CACHE.get(&id) {
|
||||||
Some(item) => match item.object_type() {
|
Some(i) => view! {
|
||||||
// special case for placeholder activities
|
<Item item=i />
|
||||||
Some(apb::ObjectType::Note) => view! {
|
<hr />
|
||||||
<Object object=item.clone() />
|
}.into_view(),
|
||||||
<hr/ >
|
|
||||||
}.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! { <Object object=obj /> }
|
|
||||||
}.into_view()),
|
|
||||||
apb::ActivityType::Follow =>
|
|
||||||
CACHE.get(&object_id).map(|obj| {
|
|
||||||
view! {
|
|
||||||
<div class="ml-1">
|
|
||||||
<ActorBanner object=obj />
|
|
||||||
<FollowRequestButtons activity_id=id actor_id=object_id />
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
}.into_view()),
|
|
||||||
_ => None,
|
|
||||||
};
|
|
||||||
view! {
|
|
||||||
<ActivityLine activity=item />
|
|
||||||
{object}
|
|
||||||
<hr/ >
|
|
||||||
}.into_view()
|
|
||||||
},
|
|
||||||
// should never happen
|
|
||||||
_ => view! { <p><code>type not implemented</code></p><hr /> }.into_view(),
|
|
||||||
},
|
|
||||||
None => view! {
|
None => view! {
|
||||||
<p><code>{id}</code>" "[<a href={uri}>go</a>]</p>
|
<p><code>{id}</code>" "[<a href={uri}>go</a>]</p>
|
||||||
|
<hr />
|
||||||
}.into_view(),
|
}.into_view(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue