//! Publication detail: right pane showing full reference fields. use leptos::prelude::*; use brittle_model::Reference; /// Right pane: displays the fields of the currently selected reference. /// /// When `reference` is `None`, a placeholder is shown. #[component] pub fn PubDetail(reference: RwSignal>) -> impl IntoView { use leptos::either::Either; view! {
{move || match reference.get() { None => Either::Left(view! {
"Select a publication to see details"
}), Some(r) => Either::Right(view! {

{r.fields.get("title").cloned().unwrap_or_else(|| "[no title]".into())}

// Entry type + cite key
"Type"
{r.entry_type.to_string()}
"Cite key"
{r.cite_key.clone()}
// Authors {if r.authors.is_empty() { None } else { let names = r.authors.iter() .map(|p| p.display_name()) .collect::>() .join("; "); Some(view! {
"Authors"
{names}
}) }} // Editors {if r.editors.is_empty() { None } else { let names = r.editors.iter() .map(|p| p.display_name()) .collect::>() .join("; "); Some(view! {
"Editors"
{names}
}) }} // Prioritised well-known fields {PRIORITY_FIELDS.iter().filter_map(|&key| { r.fields.get(key).map(|val| view! {
{field_label(key)}
{val.clone()}
}) }).collect::>()} // Remaining fields in alphabetical order {r.fields.iter() .filter(|(k, _)| !PRIORITY_FIELDS.contains(&k.as_str()) && *k != "title") .map(|(k, v)| view! {
{field_label(k)}
{v.clone()}
}) .collect::>() }

"Modified: "{r.modified_at.format("%Y-%m-%d %H:%M UTC").to_string()}

}), }}
} } /// Fields shown before the alphabetical remainder (excluding "title"). const PRIORITY_FIELDS: &[&str] = &["year", "journal", "booktitle", "volume", "doi", "abstract"]; /// Pretty-print a BibTeX field key. fn field_label(key: &str) -> String { match key { "doi" => "DOI".into(), "isbn" => "ISBN".into(), "issn" => "ISSN".into(), "url" => "URL".into(), _ => { let mut s = key.replace('_', " "); if let Some(c) = s.get_mut(0..1) { c.make_ascii_uppercase(); } s } } }