chore(web): separated ActorStrip component

This commit is contained in:
əlemi 2024-05-01 16:45:27 +02:00
parent 9fe3cb3bda
commit 102414e1a3
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 16 additions and 9 deletions

View file

@ -1,9 +1,7 @@
use std::sync::Arc;
use leptos::*; use leptos::*;
use crate::prelude::*; use crate::prelude::*;
use apb::{target::Addressed, Activity, Actor, Base, Object}; use apb::{target::Addressed, Activity, Object};
#[component] #[component]
@ -11,15 +9,12 @@ pub fn ActivityLine(activity: crate::Object) -> impl IntoView {
let object_id = activity.object().id().unwrap_or_default(); let object_id = activity.object().id().unwrap_or_default();
let actor_id = activity.actor().id().unwrap_or_default(); let actor_id = activity.actor().id().unwrap_or_default();
let actor = CACHE.get_or(&actor_id, serde_json::Value::String(actor_id.clone()).into()); let actor = CACHE.get_or(&actor_id, serde_json::Value::String(actor_id.clone()).into());
let avatar = actor.icon().get().map(|x| x.url().id().unwrap_or_default()).unwrap_or_default();
let username = actor.preferred_username().unwrap_or_default().to_string();
let domain = actor.id().unwrap_or_default().replace("https://", "").split('/').next().unwrap_or_default().to_string();
let kind = activity.activity_type().unwrap_or(apb::ActivityType::Activity); let kind = activity.activity_type().unwrap_or(apb::ActivityType::Activity);
view! { view! {
<div> <div>
<a href={Uri::web(FetchKind::User, &actor_id)} class="clean hover"> <span class="ml-1-r">
<img src={avatar} class="avatar-inline mr-s ml-1-r" /><b>{username}</b><small>@{domain}</small> <ActorStrip object=actor />
</a> </span>
<span style="float:right"> <span style="float:right">
<code class="color moreinfo" title={activity.published().map(|x| x.to_rfc2822())} > <code class="color moreinfo" title={activity.published().map(|x| x.to_rfc2822())} >
<a class="upub-title clean" title={object_id.clone()} href={Uri::web(FetchKind::Object, &object_id)} > <a class="upub-title clean" title={object_id.clone()} href={Uri::web(FetchKind::Object, &object_id)} >

View file

@ -3,6 +3,18 @@ use crate::prelude::*;
use apb::{Actor, Base, Object}; use apb::{Actor, Base, Object};
#[component]
pub fn ActorStrip(object: crate::Object) -> impl IntoView {
let actor_id = object.id().unwrap_or_default().to_string();
let username = object.preferred_username().unwrap_or_default().to_string();
let domain = object.id().unwrap_or_default().replace("https://", "").split('/').next().unwrap_or_default().to_string();
let avatar = object.icon().get().map(|x| x.url().id().unwrap_or_default()).unwrap_or_default();
view! {
<a href={Uri::web(FetchKind::User, &actor_id)} class="clean hover">
<img src={avatar} class="avatar-inline mr-s" /><b>{username}</b><small>@{domain}</small>
</a>
}
}
#[component] #[component]
pub fn ActorBanner(object: crate::Object) -> impl IntoView { pub fn ActorBanner(object: crate::Object) -> impl IntoView {