From a24f45613681739c188e5da3015da28f40becf94 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Wed, 3 Apr 2024 20:28:51 -0700 Subject: [PATCH] web: don't show mime type on attachment --- web/graphql/schema.json | 42 ++++- web/graphql/show_thread.graphql | 3 + web/index.html | 288 +------------------------------- web/src/view/mod.rs | 51 +++++- web/static/style.css | 2 +- 5 files changed, 96 insertions(+), 290 deletions(-) diff --git a/web/graphql/schema.json b/web/graphql/schema.json index 755b113..a6f2c07 100644 --- a/web/graphql/schema.json +++ b/web/graphql/schema.json @@ -65,6 +65,38 @@ "description": null, "enumValues": null, "fields": [ + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "id", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "idx", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + }, { "args": [], "deprecationReason": null, @@ -84,9 +116,13 @@ "isDeprecated": false, "name": "size", "type": { - "kind": "SCALAR", - "name": "Int", - "ofType": null + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "Int", + "ofType": null + } } }, { diff --git a/web/graphql/show_thread.graphql b/web/graphql/show_thread.graphql index 332dfff..e4dc9e7 100644 --- a/web/graphql/show_thread.graphql +++ b/web/graphql/show_thread.graphql @@ -35,9 +35,12 @@ query ShowThreadQuery($threadId: String!) { } path attachments { + id + idx filename contentType contentId + size } } } diff --git a/web/index.html b/web/index.html index 1e15a34..e9e7f67 100644 --- a/web/index.html +++ b/web/index.html @@ -4,296 +4,24 @@ - + + + + - diff --git a/web/src/view/mod.rs b/web/src/view/mod.rs index 983bfb3..cbea814 100644 --- a/web/src/view/mod.rs +++ b/web/src/view/mod.rs @@ -642,14 +642,53 @@ fn message_render(msg: &ShowThreadQueryThreadMessages, open: bool) -> Node C!["view-part-text-html"], raw![contents], IF!(!msg.attachments.is_empty() => - div![ - C!["attachments"], - hr![], - h2!["Attachments"], + div![ + C!["attachments"], + hr![], + h2!["Attachments"], + div![C!["grid","is-col-min-6"], msg.attachments .iter() - .map(|a| div!["Filename: ", &a.filename, " ", &a.content_type]) - ]), + .map(|a| { + let default = "UNKNOWN_FILE".to_string(); + 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); + + div![ + C!["attachment", "card"], + a.content_type.as_ref().map(|content_type| + IF!(content_type.starts_with("image/") => + div![C!["card-image","is-1by1"], + div![ + C!["image","is-1by1"], + style!{ + St::BackgroundImage=>format!(r#"url("{url}");"#), + St::BackgroundSize=>"cover", + St::BackgroundPosition=>"center", + } + ] + ] + )), + div![C!["card-content"], + div![C!["content"], + &a.filename, br![], + small![&a.size, " bytes"] + ] + ], + footer![ + C!["card-footer"], + a![C!["card-footer-item"],span![C!["icon"], i![C!["fas", "fa-download"]]], + ev(Ev::Click, move |_| { + seed::window().location().set_href(&url + ).expect("failed to set URL"); + }) + ] + ] + ] + }) + ] + ]), view_content_tree(&content_tree), ], } diff --git a/web/static/style.css b/web/static/style.css index dd71104..936575f 100644 --- a/web/static/style.css +++ b/web/static/style.css @@ -143,7 +143,7 @@ to { input, .input { - color: #fff; + color: #000; } input::placeholder,