Improve search behavior and squelch verbose logging.
This commit is contained in:
parent
431df7da3b
commit
c81819dc87
1539
Cargo.lock
generated
1539
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,11 @@ fn hello() -> &'static str {
|
||||
"Hello, world!"
|
||||
}
|
||||
|
||||
#[get("/search")]
|
||||
async fn search_all(nm: &State<Notmuch>) -> Result<Json<SearchSummary>, Debug<NotmuchError>> {
|
||||
search(nm, "*").await
|
||||
}
|
||||
|
||||
#[get("/search/<query>")]
|
||||
async fn search(
|
||||
nm: &State<Notmuch>,
|
||||
@ -103,7 +108,10 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
||||
.to_cors()?;
|
||||
|
||||
let _ = rocket::build()
|
||||
.mount("/", routes![original_part, original, hello, search, show])
|
||||
.mount(
|
||||
"/",
|
||||
routes![original_part, original, hello, search_all, search, show],
|
||||
)
|
||||
.attach(cors)
|
||||
.manage(Notmuch::default())
|
||||
//.manage(Notmuch::with_config("../notmuch/testdata/notmuch.config"))
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
// but some rules are too "annoying" or are not applicable for your case.)
|
||||
#![allow(clippy::wildcard_imports)]
|
||||
|
||||
use log::{error, info, Level};
|
||||
use log::{debug, error, info, Level};
|
||||
use notmuch::{Content, Part, SearchSummary, ThreadNode, ThreadSet};
|
||||
use seed::{prelude::*, *};
|
||||
|
||||
@ -19,6 +19,7 @@ fn init(_: Url, orders: &mut impl Orders<Msg>) -> Model {
|
||||
Model {
|
||||
search_results: None,
|
||||
show_results: None,
|
||||
query: "".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,6 +31,7 @@ fn init(_: Url, orders: &mut impl Orders<Msg>) -> Model {
|
||||
struct Model {
|
||||
search_results: Option<SearchSummary>,
|
||||
show_results: Option<ThreadSet>,
|
||||
query: String,
|
||||
}
|
||||
|
||||
// ------ ------
|
||||
@ -39,6 +41,7 @@ struct Model {
|
||||
// (Remove the line below once any of your `Msg` variants doesn't implement `Copy`.)
|
||||
// `Msg` describes the different events you can modify state with.
|
||||
enum Msg {
|
||||
Noop,
|
||||
SearchRequest(String),
|
||||
SearchResult(fetch::Result<SearchSummary>),
|
||||
ShowRequest(String),
|
||||
@ -48,15 +51,17 @@ enum Msg {
|
||||
// `update` describes how to handle each `Msg`.
|
||||
fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
match msg {
|
||||
Msg::Noop => {}
|
||||
Msg::SearchRequest(query) => {
|
||||
model.show_results = None;
|
||||
model.query = query.clone();
|
||||
orders
|
||||
.skip()
|
||||
.perform_cmd(async move { Msg::SearchResult(search_request(&query).await) });
|
||||
}
|
||||
|
||||
Msg::SearchResult(Ok(response_data)) => {
|
||||
info!("fetch ok {:#?}", response_data);
|
||||
debug!("fetch ok {:#?}", response_data);
|
||||
model.search_results = Some(response_data);
|
||||
}
|
||||
|
||||
@ -71,7 +76,7 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
}
|
||||
|
||||
Msg::ShowResult(Ok(response_data)) => {
|
||||
info!("fetch ok {:#?}", response_data);
|
||||
debug!("fetch ok {:#?}", response_data);
|
||||
model.show_results = Some(response_data);
|
||||
}
|
||||
|
||||
@ -317,21 +322,26 @@ fn view(model: &Model) -> Node<Msg> {
|
||||
} else {
|
||||
div![h1!["Loading"]]
|
||||
};
|
||||
let query = model.query.clone();
|
||||
div![
|
||||
button![
|
||||
"Unread",
|
||||
ev(Ev::Click, |_| Msg::SearchRequest("is:unread".to_string())),
|
||||
],
|
||||
button![
|
||||
"All",
|
||||
ev(Ev::Click, |_| Msg::SearchRequest("*".to_string())),
|
||||
],
|
||||
button!["All", ev(Ev::Click, |_| Msg::SearchRequest("".to_string())),],
|
||||
input![
|
||||
attrs! {
|
||||
At::Placeholder => "Search";
|
||||
At::AutoFocus => true.as_at_value();
|
||||
At::Value => query,
|
||||
},
|
||||
input_ev(Ev::Input, Msg::SearchRequest),
|
||||
// Resend search on enter.
|
||||
keyboard_ev(Ev::KeyUp, |e| if e.key_code() == 0x0d {
|
||||
Msg::SearchRequest(query)
|
||||
} else {
|
||||
Msg::Noop
|
||||
}),
|
||||
],
|
||||
content
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user