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