use dioxus::prelude::*; use polymodel_api::space_polymodel::library; #[component] pub(crate) fn AuthorByline(actor: library::Actor, class: String) -> Element { let href = profile_href(&actor); let display_name = clean_text(actor.display_name.as_ref().map(AsRef::as_ref)); let handle = actor.handle.as_ref(); rsx! { p { class, a { class: "author-byline-link", href, if let Some(display_name) = display_name { span { class: "author-byline-name", "{display_name}" } span { class: "author-byline-handle author-byline-handle-secondary", " @{handle}" } } else { span { class: "author-byline-handle", "@{handle}" } } } } } } pub(crate) fn profile_href(actor: &library::Actor) -> String { let handle = actor.handle.as_ref(); if !handle.is_empty() { format!("/profile/{handle}") } else { format!("/profile/{}", actor.did.as_ref()) } } fn clean_text(value: Option<&str>) -> Option<&str> { value.map(str::trim).filter(|value| !value.is_empty()) } #[cfg(test)] mod tests { use jacquard_common::types::string::{Did, Handle}; use super::*; fn fixture_actor(did: &str, handle: &str) -> library::Actor { library::Actor { avatar: None, description: None, did: Did::new_owned(did).expect("fixture DID is valid"), display_name: Some("Maker Name".into()), follower_count: None, following_count: None, handle: Handle::new_owned(handle).expect("fixture handle is valid"), pronouns: None, thing_count: None, viewer: None, extra_data: None, } } #[test] fn profile_href_prefers_handle() { let actor = fixture_actor("did:plc:alice", "alice.test"); assert_eq!(profile_href(&actor), "/profile/alice.test"); } }