web: human format attachment size

This commit is contained in:
Bill Thiede 2024-04-06 08:52:20 -07:00
parent 1f5f10f78d
commit dc7b3dd3e8
2 changed files with 12 additions and 7 deletions

View File

@ -32,6 +32,7 @@ graphql_client = "0.13.0"
thiserror = "1.0.50"
seed_hooks = { git = "https://github.com/wathiede/styles_hooks", package = "seed_hooks", branch = "main" }
gloo-net = { version = "0.4.0", features = ["json", "serde_json"] }
human_format = { git ="https://github.com/wathiede/human-format-rs" }
[package.metadata.wasm-pack.profile.release]
wasm-opt = ['-Os']

View File

@ -4,6 +4,7 @@ use std::{
};
use chrono::{DateTime, Datelike, Duration, Local, Utc};
use human_format::{Formatter, Scales};
use itertools::Itertools;
use log::error;
use seed::{prelude::*, *};
@ -641,18 +642,18 @@ fn message_render(msg: &ShowThreadQueryThreadMessages, open: bool) -> Node<Msg>
) => pre![C!["error"], contents],
ShowThreadQueryThreadMessagesBody::PlainText(
ShowThreadQueryThreadMessagesBodyOnPlainText {
contents,
content_tree,
},
contents,
content_tree,
},
) => div![
raw_text_message(&contents),
view_content_tree(&content_tree),
],
ShowThreadQueryThreadMessagesBody::Html(
ShowThreadQueryThreadMessagesBodyOnHtml {
contents,
content_tree,
},
contents,
content_tree,
},
) => div![
C!["view-part-text-html"],
raw![contents],
@ -669,6 +670,9 @@ fn message_render(msg: &ShowThreadQueryThreadMessages, open: bool) -> Node<Msg>
let filename = a.filename.as_ref().unwrap_or(&default);
let host = seed::window().location().host().expect("couldn't get host");
let url = format!("//{host}/download/attachment/{}/{}/{}", a.id,a.idx, filename);
let mut fmtr = Formatter::new();
fmtr.with_separator(" ");
fmtr.with_scales(Scales::Binary());
div![
C!["attachment", "card"],
@ -688,7 +692,7 @@ fn message_render(msg: &ShowThreadQueryThreadMessages, open: bool) -> Node<Msg>
div![C!["card-content"],
div![C!["content"],
&a.filename, br![],
small![&a.size, " bytes"]
small![ fmtr.format(a.size as f64),"B"]
]
],
footer![