diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-11-06 23:58:59 +0100 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-11-06 23:59:25 +0100 |
commit | c50cc4cf2ce8ba299e6d5b24f9e16b55e1f800ac (patch) | |
tree | 2d6f75fd69370dc6c56f4bd87379490ca583a8bb | |
parent | Frontend: Display a loading animation when results have not been loaded (diff) | |
download | OSSE-c50cc4cf2ce8ba299e6d5b24f9e16b55e1f800ac.tar.gz OSSE-c50cc4cf2ce8ba299e6d5b24f9e16b55e1f800ac.tar.bz2 OSSE-c50cc4cf2ce8ba299e6d5b24f9e16b55e1f800ac.zip |
Frontend: Append "..." to truncated titles and descriptions
-rw-r--r-- | frontend/src/app.rs | 16 |
1 files 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 { <p class="title mb-1">{match props.result.title.clone() { None => "No Title".to_string(), Some(title) => { - truncate(&title, 70).to_string()//TODO: add ... if truncate + truncate(&title, 70) }, }}</p> </a> @@ -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)} </p> |