Add render time to footer.

This commit is contained in:
Bill Thiede 2023-02-28 19:06:07 -08:00
parent d8275debdc
commit 369e88880a
4 changed files with 102 additions and 39 deletions

45
Cargo.lock generated
View File

@ -982,6 +982,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"wasm-bindgen-test", "wasm-bindgen-test",
"wasm-timer",
] ]
[[package]] [[package]]
@ -1242,6 +1243,17 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "parking_lot"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
dependencies = [
"instant",
"lock_api",
"parking_lot_core 0.8.6",
]
[[package]] [[package]]
name = "parking_lot" name = "parking_lot"
version = "0.12.1" version = "0.12.1"
@ -1249,7 +1261,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [ dependencies = [
"lock_api", "lock_api",
"parking_lot_core", "parking_lot_core 0.9.4",
]
[[package]]
name = "parking_lot_core"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"
dependencies = [
"cfg-if 1.0.0",
"instant",
"libc",
"redox_syscall",
"smallvec",
"winapi 0.3.9",
] ]
[[package]] [[package]]
@ -1572,7 +1598,7 @@ dependencies = [
"memchr", "memchr",
"multer", "multer",
"num_cpus", "num_cpus",
"parking_lot", "parking_lot 0.12.1",
"pin-project-lite", "pin-project-lite",
"rand", "rand",
"ref-cast", "ref-cast",
@ -2443,6 +2469,21 @@ dependencies = [
"quote 1.0.21", "quote 1.0.21",
] ]
[[package]]
name = "wasm-timer"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be0ecb0db480561e9a7642b5d3e4187c128914e58aa84330b9493e3eb68c5e7f"
dependencies = [
"futures",
"js-sys",
"parking_lot 0.11.2",
"pin-utils",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
]
[[package]] [[package]]
name = "web-sys" name = "web-sys"
version = "0.3.60" version = "0.3.60"

View File

@ -24,6 +24,7 @@ serde = { version = "1.0.147", features = ["derive"] }
notmuch = {path = "../notmuch"} notmuch = {path = "../notmuch"}
itertools = "0.10.5" 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"
[package.metadata.wasm-pack.profile.release] [package.metadata.wasm-pack.profile.release]
wasm-opt = ['-Os'] wasm-opt = ['-Os']

View File

@ -14,7 +14,6 @@
} }
.body { .body {
padding-bottom: 1em; padding-bottom: 1em;
border: 1px red solid;
} }
.error { .error {
background-color: red; background-color: red;
@ -34,6 +33,15 @@ iframe {
.index .date { .index .date {
white-space: nowrap; white-space: nowrap;
} }
.footer {
background-color: #eee;
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 3em;
padding: 1em;
}
</style> </style>
</head> </head>

View File

@ -8,6 +8,7 @@ use log::{debug, error, info, warn, Level};
use notmuch::{Content, Part, SearchSummary, Thread, ThreadNode, ThreadSet}; use notmuch::{Content, Part, SearchSummary, Thread, ThreadNode, ThreadSet};
use seed::{prelude::*, *}; use seed::{prelude::*, *};
use serde::de::Deserialize; use serde::de::Deserialize;
use wasm_timer::Instant;
// ------ ------ // ------ ------
// Init // Init
@ -295,8 +296,8 @@ fn pretty_authors(authors: &str) -> impl Iterator<Item = Node<Msg>> + '_ {
} }
*/ */
authors Itertools::intersperse(
.filter_map(|author| { authors.filter_map(|author| {
author.split_whitespace().nth(0).map(|first| { author.split_whitespace().nth(0).map(|first| {
span![ span![
attrs! { attrs! {
@ -304,8 +305,9 @@ fn pretty_authors(authors: &str) -> impl Iterator<Item = Node<Msg>> + '_ {
first first
] ]
}) })
}) }),
.intersperse(span![", "]) span![", "],
)
} }
fn view_search_results(query: &str, search_results: &SearchSummary) -> Node<Msg> { fn view_search_results(query: &str, search_results: &SearchSummary) -> Node<Msg> {
@ -398,8 +400,6 @@ fn view_header(query: &str) -> Node<Msg> {
nav![ nav![
C!["navbar"], C!["navbar"],
attrs! {At::Role=>"navigation"}, attrs! {At::Role=>"navigation"},
div![
C!["navbar-menu"],
div![ div![
C!["navbar-start"], C!["navbar-start"],
a![ a![
@ -429,22 +429,35 @@ fn view_header(query: &str) -> Node<Msg> {
] ]
] ]
] ]
}
fn view_footer(render_time_ms: u128) -> Node<Msg> {
footer![
C!["footer"],
div![
C!["content", "has-text-right", "is-size-7"],
format!("Render time {} ms", render_time_ms)
]
] ]
} }
// `view` describes what to display. // `view` describes what to display.
fn view(model: &Model) -> Node<Msg> { fn view(model: &Model) -> Node<Msg> {
let start = Instant::now();
info!("view called"); info!("view called");
let content = match &model.context { let content = match &model.context {
Context::None => div![h1!["Loading"]], Context::None => div![h1!["Loading"]],
Context::Thread(thread_set) => view_thread(thread_set), Context::Thread(thread_set) => view_thread(thread_set),
Context::Search(search_results) => view_search_results(&model.query, search_results), Context::Search(search_results) => view_search_results(&model.query, search_results),
}; };
div![section![ div![
C!["section"],
view_header(&model.query), view_header(&model.query),
div![C!["container"], content] section![
]] C!["section"],
div![C!["container"], content],
view_footer(start.elapsed().as_millis())
]
]
} }
// ------ ------ // ------ ------