Move to "show pretty" currently a dupe of 'show'.
This commit is contained in:
parent
369e88880a
commit
c33f901f48
@ -32,6 +32,15 @@ async fn search(
|
|||||||
Ok(Json(res))
|
Ok(Json(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/show/<query>/pretty")]
|
||||||
|
async fn show_pretty(
|
||||||
|
nm: &State<Notmuch>,
|
||||||
|
query: &str,
|
||||||
|
) -> Result<Json<ThreadSet>, Debug<NotmuchError>> {
|
||||||
|
let res = nm.show(query)?;
|
||||||
|
Ok(Json(res))
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/show/<query>")]
|
#[get("/show/<query>")]
|
||||||
async fn show(nm: &State<Notmuch>, query: &str) -> Result<Json<ThreadSet>, Debug<NotmuchError>> {
|
async fn show(nm: &State<Notmuch>, query: &str) -> Result<Json<ThreadSet>, Debug<NotmuchError>> {
|
||||||
let res = nm.show(query)?;
|
let res = nm.show(query)?;
|
||||||
@ -110,7 +119,15 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let _ = rocket::build()
|
let _ = rocket::build()
|
||||||
.mount(
|
.mount(
|
||||||
"/",
|
"/",
|
||||||
routes![original_part, original, hello, search_all, search, show],
|
routes![
|
||||||
|
original_part,
|
||||||
|
original,
|
||||||
|
hello,
|
||||||
|
search_all,
|
||||||
|
search,
|
||||||
|
show_pretty,
|
||||||
|
show
|
||||||
|
],
|
||||||
)
|
)
|
||||||
.attach(cors)
|
.attach(cors)
|
||||||
.manage(Notmuch::default())
|
.manage(Notmuch::default())
|
||||||
|
|||||||
@ -42,6 +42,9 @@ iframe {
|
|||||||
height: 3em;
|
height: 3em;
|
||||||
padding: 1em;
|
padding: 1em;
|
||||||
}
|
}
|
||||||
|
.tag {
|
||||||
|
margin-right: 2px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,10 @@
|
|||||||
// - it's useful when you want to check your code with `cargo make verify`
|
// - it's useful when you want to check your code with `cargo make verify`
|
||||||
// but some rules are too "annoying" or are not applicable for your case.)
|
// but some rules are too "annoying" or are not applicable for your case.)
|
||||||
#![allow(clippy::wildcard_imports)]
|
#![allow(clippy::wildcard_imports)]
|
||||||
|
use std::{
|
||||||
|
collections::hash_map::DefaultHasher,
|
||||||
|
hash::{Hash, Hasher},
|
||||||
|
};
|
||||||
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::{debug, error, info, warn, Level};
|
use log::{debug, error, info, warn, Level};
|
||||||
@ -25,7 +29,7 @@ fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
|||||||
match hpp {
|
match hpp {
|
||||||
Some("t") => {
|
Some("t") => {
|
||||||
let tid = url.next_hash_path_part().unwrap_or("").to_string();
|
let tid = url.next_hash_path_part().unwrap_or("").to_string();
|
||||||
orders.send_msg(Msg::ShowRequest(tid));
|
orders.send_msg(Msg::ShowPrettyRequest(tid));
|
||||||
}
|
}
|
||||||
Some("s") => {
|
Some("s") => {
|
||||||
query = url.next_hash_path_part().unwrap_or("").to_string();
|
query = url.next_hash_path_part().unwrap_or("").to_string();
|
||||||
@ -74,6 +78,8 @@ enum Msg {
|
|||||||
SearchResult(fetch::Result<SearchSummary>),
|
SearchResult(fetch::Result<SearchSummary>),
|
||||||
ShowRequest(String),
|
ShowRequest(String),
|
||||||
ShowResult(fetch::Result<ThreadSet>),
|
ShowResult(fetch::Result<ThreadSet>),
|
||||||
|
ShowPrettyRequest(String),
|
||||||
|
ShowPrettyResult(fetch::Result<ThreadSet>),
|
||||||
}
|
}
|
||||||
|
|
||||||
// `update` describes how to handle each `Msg`.
|
// `update` describes how to handle each `Msg`.
|
||||||
@ -111,6 +117,21 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
|||||||
Msg::ShowResult(Err(fetch_error)) => {
|
Msg::ShowResult(Err(fetch_error)) => {
|
||||||
error!("fetch failed {:?}", fetch_error);
|
error!("fetch failed {:?}", fetch_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Msg::ShowPrettyRequest(tid) => {
|
||||||
|
let url = Url::new().set_hash_path(["t", &tid]);
|
||||||
|
orders.request_url(url);
|
||||||
|
orders
|
||||||
|
.skip()
|
||||||
|
.perform_cmd(async move { Msg::ShowPrettyResult(show_pretty_request(&tid).await) });
|
||||||
|
}
|
||||||
|
Msg::ShowPrettyResult(Ok(response_data)) => {
|
||||||
|
debug!("fetch ok {:#?}", response_data);
|
||||||
|
model.context = Context::Thread(response_data);
|
||||||
|
}
|
||||||
|
Msg::ShowPrettyResult(Err(fetch_error)) => {
|
||||||
|
error!("fetch failed {:?}", fetch_error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,6 +153,9 @@ mod api {
|
|||||||
pub fn show(tid: &str) -> String {
|
pub fn show(tid: &str) -> String {
|
||||||
format!("{}/show/{}", BASE_URL, tid)
|
format!("{}/show/{}", BASE_URL, tid)
|
||||||
}
|
}
|
||||||
|
pub fn show_pretty(tid: &str) -> String {
|
||||||
|
format!("{}/show/{}/pretty", BASE_URL, tid)
|
||||||
|
}
|
||||||
pub fn original(message_id: &str) -> String {
|
pub fn original(message_id: &str) -> String {
|
||||||
format!("{}/original/{}", BASE_URL, message_id)
|
format!("{}/original/{}", BASE_URL, message_id)
|
||||||
}
|
}
|
||||||
@ -151,6 +175,16 @@ async fn show_request(tid: &str) -> fetch::Result<ThreadSet> {
|
|||||||
.map_err(|_| FetchError::JsonError(fetch::JsonError::Serde(JsValue::NULL)))?)
|
.map_err(|_| FetchError::JsonError(fetch::JsonError::Serde(JsValue::NULL)))?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn show_pretty_request(tid: &str) -> fetch::Result<ThreadSet> {
|
||||||
|
Request::new(api::show_pretty(tid))
|
||||||
|
.method(Method::Get)
|
||||||
|
.fetch()
|
||||||
|
.await?
|
||||||
|
.check_status()?
|
||||||
|
.json()
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
// ------ ------
|
// ------ ------
|
||||||
// View
|
// View
|
||||||
// ------ ------
|
// ------ ------
|
||||||
@ -274,30 +308,32 @@ fn set_title(title: &str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn tags_chiclet(tags: &[String]) -> impl Iterator<Item = Node<Msg>> + '_ {
|
fn tags_chiclet(tags: &[String]) -> impl Iterator<Item = Node<Msg>> + '_ {
|
||||||
tags.iter().map(|tag| match tag.as_str() {
|
tags.iter().map(|tag| {
|
||||||
"attachment" => span![C!["tag"], "📎"],
|
let mut hasher = DefaultHasher::new();
|
||||||
"replied" => span![C!["tag"], i![C!["fa-solid", "fa-reply"]]],
|
tag.hash(&mut hasher);
|
||||||
_ => span![C!["tag"], tag],
|
let hex = format!("#{:06x}", hasher.finish() % (1 << 24));
|
||||||
|
let style = style! {St::BackgroundColor=>hex};
|
||||||
|
match tag.as_str() {
|
||||||
|
"attachment" => span![C!["tag"], style, "📎"],
|
||||||
|
"replied" => span![C!["tag"], style, i![C!["fa-solid", "fa-reply"]]],
|
||||||
|
_ => span![C!["tag"], style, tag],
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pretty_authors(authors: &str) -> impl Iterator<Item = Node<Msg>> + '_ {
|
fn pretty_authors(authors: &str) -> impl Iterator<Item = Node<Msg>> + '_ {
|
||||||
|
let one_person = authors.matches(',').count() == 0;
|
||||||
let authors = authors.split(',');
|
let authors = authors.split(',');
|
||||||
|
|
||||||
/*
|
Itertools::intersperse(
|
||||||
if authors.len() == 1 {
|
authors.filter_map(move |author| {
|
||||||
return authors.iter().filter_map(|author| {
|
if one_person {
|
||||||
Some(span![
|
return Some(span![
|
||||||
attrs! {
|
attrs! {
|
||||||
At::Title => author.trim()},
|
At::Title => author.trim()},
|
||||||
author
|
author
|
||||||
])
|
]);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
Itertools::intersperse(
|
|
||||||
authors.filter_map(|author| {
|
|
||||||
author.split_whitespace().nth(0).map(|first| {
|
author.split_whitespace().nth(0).map(|first| {
|
||||||
span![
|
span![
|
||||||
attrs! {
|
attrs! {
|
||||||
@ -326,7 +362,7 @@ fn view_search_results(query: &str, search_results: &SearchSummary) -> Node<Msg>
|
|||||||
],
|
],
|
||||||
td![C!["subject"], tags_chiclet(&r.tags), " ", &r.subject],
|
td![C!["subject"], tags_chiclet(&r.tags), " ", &r.subject],
|
||||||
td![C!["date"], &r.date_relative],
|
td![C!["date"], &r.date_relative],
|
||||||
ev(Ev::Click, move |_| Msg::ShowRequest(tid)),
|
ev(Ev::Click, move |_| Msg::ShowPrettyRequest(tid)),
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
div![table![
|
div![table![
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user