Only add ellipsis if the truncate actually happened

This commit is contained in:
Yash Karandikar 2021-10-23 21:31:04 -05:00
parent 0cab61a885
commit 97223bb06a
Signed by: karx
GPG key ID: A794DA2529474BA5

View file

@ -1,6 +1,9 @@
use sycamore::prelude::*;
use crate::{AppMode, date::{get_current_time_millis, time_hr}, local_storage, log};
use crate::{
date::{get_current_time_millis, time_hr},
local_storage, log, AppMode,
};
#[derive(Clone, Debug)]
pub struct DefaultViewProps {
@ -15,10 +18,10 @@ impl DefaultViewProps {
}
fn truncate(s: String, max_chars: usize) -> String {
format!("{}...", match s.char_indices().nth(max_chars) {
match s.char_indices().nth(max_chars) {
None => s,
Some((idx, _)) => (&s[..idx]).to_string()
})
Some((idx, _)) => format!("{}...", &s[..idx]),
}
}
#[component(DefaultView<G>)]
@ -36,8 +39,8 @@ pub fn default_view(props: DefaultViewProps) -> Template<G> {
let note = local_storage::get_item(&res);
let trunced = truncate(note, 100);
new_vec.push(template! {
div(class="card") {
new_vec.push(template! {
div(class="card") {
(trunced)
br
br