From 1194e674cb193d032ef9d2374d81bc5cbd91de2e Mon Sep 17 00:00:00 2001 From: Baitinq Date: Sun, 6 Nov 2022 20:08:24 +0100 Subject: Frontend: Display a maximum number of chars for title and desc --- frontend/src/app.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/frontend/src/app.rs b/frontend/src/app.rs index 02f46a3..4e6e62d 100644 --- a/frontend/src/app.rs +++ b/frontend/src/app.rs @@ -40,16 +40,30 @@ fn result_component(props: &ResultComponentProps) -> Html { .unwrap(); let style = style.get_class_name().to_owned(); + fn truncate(s: &str, max_chars: usize) -> &str { + match s.char_indices().nth(max_chars) { + None => s, + Some((idx, _)) => &s[..idx], + } + } + html! {

{props.result.url.clone()}

-

{props.result.title.clone()}

+

{match props.result.title.clone() { + None => "No Title".to_string(), + Some(title) => { + truncate(&title, 70).to_string() + }, + }}

{match props.result.description.clone() { None => "No Description.".to_string(), - Some(description) => description.to_owned(), + Some(description) => { + truncate(&description, 200).to_string() + }, }}{format!("PRIO: {}", props.result.priority)}

-- cgit 1.4.1