Custom formatting of the age string, widen subject column.
This commit is contained in:
parent
95976c2860
commit
f6c1835b18
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -222,15 +222,14 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "chrono"
|
name = "chrono"
|
||||||
version = "0.4.28"
|
version = "0.4.31"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "95ed24df0632f708f5f6d8082675bef2596f7084dee3dd55f632290bf35bfe0f"
|
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"android-tzdata",
|
"android-tzdata",
|
||||||
"iana-time-zone",
|
"iana-time-zone",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"time 0.1.45",
|
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"windows-targets",
|
"windows-targets",
|
||||||
]
|
]
|
||||||
@ -1243,6 +1242,7 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
|||||||
name = "letterbox"
|
name = "letterbox"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
"console_error_panic_hook",
|
"console_error_panic_hook",
|
||||||
"console_log",
|
"console_log",
|
||||||
"css-inline",
|
"css-inline",
|
||||||
|
|||||||
@ -27,6 +27,7 @@ itertools = "0.10.5"
|
|||||||
serde_json = { version = "1.0.93", features = ["unbounded_depth"] }
|
serde_json = { version = "1.0.93", features = ["unbounded_depth"] }
|
||||||
wasm-timer = "0.2.5"
|
wasm-timer = "0.2.5"
|
||||||
css-inline = "0.8.5"
|
css-inline = "0.8.5"
|
||||||
|
chrono = "0.4.31"
|
||||||
|
|
||||||
[package.metadata.wasm-pack.profile.release]
|
[package.metadata.wasm-pack.profile.release]
|
||||||
wasm-opt = ['-Os']
|
wasm-opt = ['-Os']
|
||||||
|
|||||||
@ -39,7 +39,7 @@ iframe {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
width: 15em;
|
width: 10em;
|
||||||
}
|
}
|
||||||
.index .subject {
|
.index .subject {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@ -47,8 +47,9 @@ iframe {
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
.index .date {
|
.index .date {
|
||||||
width: 8em;
|
width: 6em;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
text-align: right;
|
||||||
}
|
}
|
||||||
.footer {
|
.footer {
|
||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
|
|||||||
@ -7,6 +7,7 @@ use std::{
|
|||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use chrono::{DateTime, Datelike, Duration, Local, Utc};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::{debug, error, info, Level};
|
use log::{debug, error, info, Level};
|
||||||
use notmuch::{Content, Part, Thread, ThreadNode, ThreadSet};
|
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> {
|
fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult) -> Node<Msg> {
|
||||||
if query.is_empty() {
|
if query.is_empty() {
|
||||||
set_title("all mail");
|
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 tid = r.thread.clone();
|
||||||
|
let datetime = human_age(r.timestamp as i64);
|
||||||
div![
|
div![
|
||||||
C!["row"],
|
C!["row"],
|
||||||
div![
|
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)],
|
span![C!["from", "is-size-7"], pretty_authors(&r.authors)],
|
||||||
div![
|
div![
|
||||||
span![C!["is-size-7"], tags_chiclet(&r.tags, true)],
|
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 summaries = &search_results.summary.0;
|
||||||
let rows = summaries.iter().map(|r| {
|
let rows = summaries.iter().map(|r| {
|
||||||
let tid = r.thread.clone();
|
let tid = r.thread.clone();
|
||||||
|
let datetime = human_age(r.timestamp as i64);
|
||||||
tr![
|
tr![
|
||||||
td![
|
td![
|
||||||
C!["from"],
|
C!["from"],
|
||||||
@ -554,7 +579,7 @@ fn view_search_results(query: &str, search_results: &shared::SearchResult) -> No
|
|||||||
&r.subject,
|
&r.subject,
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
td![C!["date"], &r.date_relative]
|
td![C!["date"], datetime]
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
let first = search_results.page * search_results.results_per_page;
|
let first = search_results.page * search_results.results_per_page;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user