Custom formatting of the age string, widen subject column.

This commit is contained in:
Bill Thiede 2023-11-20 17:41:58 -08:00
parent 95976c2860
commit f6c1835b18
4 changed files with 34 additions and 7 deletions

6
Cargo.lock generated
View File

@ -222,15 +222,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.28"
version = "0.4.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95ed24df0632f708f5f6d8082675bef2596f7084dee3dd55f632290bf35bfe0f"
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"time 0.1.45",
"wasm-bindgen",
"windows-targets",
]
@ -1243,6 +1242,7 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
name = "letterbox"
version = "0.1.0"
dependencies = [
"chrono",
"console_error_panic_hook",
"console_log",
"css-inline",

View File

@ -27,6 +27,7 @@ itertools = "0.10.5"
serde_json = { version = "1.0.93", features = ["unbounded_depth"] }
wasm-timer = "0.2.5"
css-inline = "0.8.5"
chrono = "0.4.31"
[package.metadata.wasm-pack.profile.release]
wasm-opt = ['-Os']

View File

@ -39,7 +39,7 @@ iframe {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 15em;
width: 10em;
}
.index .subject {
overflow: hidden;
@ -47,8 +47,9 @@ iframe {
white-space: nowrap;
}
.index .date {
width: 8em;
width: 6em;
white-space: nowrap;
text-align: right;
}
.footer {
background-color: #eee;

View File

@ -7,6 +7,7 @@ use std::{
hash::{Hash, Hasher},
};
use chrono::{DateTime, Datelike, Duration, Local, Utc};
use itertools::Itertools;
use log::{debug, error, info, Level};
use notmuch::{Content, Part, Thread, ThreadNode, ThreadSet};
@ -481,6 +482,28 @@ fn pretty_authors(authors: &str) -> impl Iterator<Item = Node<Msg>> + '_ {
)
}
fn human_age(timestamp: i64) -> String {
let now = Local::now();
let ts = DateTime::<Utc>::from_timestamp(timestamp, 0)
.unwrap()
.with_timezone(&Local);
let age = now - ts;
let weekday = now.weekday();
let datetime = if age < Duration::minutes(1) {
format!("{} ago", age.num_seconds())
} else if age < Duration::hours(1) {
format!("{} ago", age.num_minutes())
} else if age < Duration::days(1) {
ts.format("%H:%M").to_string()
} else if age < Duration::weeks(1) {
ts.format("%a %H:%M").to_string()
} else {
ts.format("%b %e").to_string()
};
info!("dateime {datetime} TZ: {}", ts.offset());
datetime
}
fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult) -> Node<Msg> {
if query.is_empty() {
set_title("all mail");
@ -503,6 +526,7 @@ fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult
]
*/
let tid = r.thread.clone();
let datetime = human_age(r.timestamp as i64);
div![
C!["row"],
div![
@ -513,7 +537,7 @@ fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult
span![C!["from", "is-size-7"], pretty_authors(&r.authors)],
div![
span![C!["is-size-7"], tags_chiclet(&r.tags, true)],
span![C!["is-size-7", "float-right", "date"], &r.date_relative]
span![C!["is-size-7", "float-right", "date"], datetime]
]
]
});
@ -536,6 +560,7 @@ fn view_search_results(query: &str, search_results: &shared::SearchResult) -> No
let summaries = &search_results.summary.0;
let rows = summaries.iter().map(|r| {
let tid = r.thread.clone();
let datetime = human_age(r.timestamp as i64);
tr![
td![
C!["from"],
@ -554,7 +579,7 @@ fn view_search_results(query: &str, search_results: &shared::SearchResult) -> No
&r.subject,
]
],
td![C!["date"], &r.date_relative]
td![C!["date"], datetime]
]
});
let first = search_results.page * search_results.results_per_page;