From 7b22f854294e5c0a1118b87831329bd9cf2cbc49 Mon Sep 17 00:00:00 2001 From: Bill Thiede Date: Sun, 10 Dec 2023 17:26:24 -0800 Subject: [PATCH] web: show union of tags when viewing thread --- web/graphql/schema.json | 24 ++++++++++++++++++++++++ web/graphql/show_thread.graphql | 1 + web/src/view/mod.rs | 23 +++++++++++++++++++---- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/web/graphql/schema.json b/web/graphql/schema.json index 384ccb7..d27b48a 100644 --- a/web/graphql/schema.json +++ b/web/graphql/schema.json @@ -504,6 +504,30 @@ } } } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "tags", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + } + } } ], "inputFields": null, diff --git a/web/graphql/show_thread.graphql b/web/graphql/show_thread.graphql index 45a17aa..fef814a 100644 --- a/web/graphql/show_thread.graphql +++ b/web/graphql/show_thread.graphql @@ -4,6 +4,7 @@ query ShowThreadQuery($threadId: String!) { messages { id subject + tags from { name addr diff --git a/web/src/view/mod.rs b/web/src/view/mod.rs index 4dd28b7..61f7bdf 100644 --- a/web/src/view/mod.rs +++ b/web/src/view/mod.rs @@ -1,5 +1,5 @@ use std::{ - collections::hash_map::DefaultHasher, + collections::{hash_map::DefaultHasher, HashSet}, hash::{Hash, Hasher}, }; @@ -265,6 +265,16 @@ fn raw_text_message(contents: &str) -> Node { fn thread(thread: &ShowThreadQueryThread) -> Node { // TODO(wathiede): show per-message subject if it changes significantly from top-level subject set_title(&thread.subject); + let mut tags: Vec<_> = thread + .messages + .iter() + .fold(HashSet::new(), |mut tags, msg| { + tags.extend(msg.tags.clone()); + tags + }) + .into_iter() + .collect(); + tags.sort(); let messages = thread.messages.iter().map(|msg| { div![ C!["message"], @@ -323,7 +333,12 @@ fn thread(thread: &ShowThreadQueryThread) -> Node { }); div![ C!["thread"], - p![C!["is-size-4"], &thread.subject], + p![ + C!["is-size-4"], + &thread.subject, + " ", + tags_chiclet(&tags, false) + ], messages, /* TODO(wathiede): plumb in orignal id a![ @@ -353,8 +368,8 @@ fn view_content_tree(content_tree: &str) -> Node { debug_open.set(!debug_open.get()); }) ], - IF!(debug_open.get() => - pre![C!["content-tree"], content_tree]), + IF!(debug_open.get() => + pre![C!["content-tree"], content_tree]), ] }