From c50cc4cf2ce8ba299e6d5b24f9e16b55e1f800ac Mon Sep 17 00:00:00 2001 From: Baitinq Date: Sun, 6 Nov 2022 23:58:59 +0100 Subject: Frontend: Append "..." to truncated titles and descriptions --- frontend/src/app.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/frontend/src/app.rs b/frontend/src/app.rs index d3edfa5..17c1e3c 100644 --- a/frontend/src/app.rs +++ b/frontend/src/app.rs @@ -40,10 +40,14 @@ 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], + fn truncate(s: &str, max_chars: usize) -> String { + match s.char_indices().nth(max_chars - 3) { + None => s.to_string(), + Some((idx, _)) => { + let mut s = s[..idx].to_string(); + s.push_str("..."); + s + } } } @@ -54,7 +58,7 @@ fn result_component(props: &ResultComponentProps) -> Html {

{match props.result.title.clone() { None => "No Title".to_string(), Some(title) => { - truncate(&title, 70).to_string()//TODO: add ... if truncate + truncate(&title, 70) }, }}

@@ -62,7 +66,7 @@ fn result_component(props: &ResultComponentProps) -> Html { {match props.result.description.clone() { None => "No Description.".to_string(), Some(description) => { - truncate(&description, 200).to_string() //TODO: add ... if truncate + truncate(&description, 200) }, }}{format!("PRIO: {}", props.result.priority)}

-- cgit 1.4.1