Compare commits
14 Commits
server-sid
...
pretty
| Author | SHA1 | Date | |
|---|---|---|---|
| 98df04527d | |||
| da15ef0f15 | |||
| 035508f3ad | |||
| 69558f15b4 | |||
| a8f538eddf | |||
| 01e5ea14ab | |||
| 042d475c75 | |||
| dd0af52feb | |||
| 130f9bbeba | |||
| 0a05b32a7a | |||
| c3f897c61a | |||
| c62bac037f | |||
| 79a57f3082 | |||
| c33de9d754 |
1564
Cargo.lock
generated
1564
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,4 +1,5 @@
|
||||
[workspace]
|
||||
resolver = "2"
|
||||
members = [
|
||||
"web",
|
||||
"server",
|
||||
|
||||
2
dev.sh
2
dev.sh
@@ -1,7 +1,7 @@
|
||||
cd -- "$( dirname -- "${BASH_SOURCE[0]}" )"
|
||||
tmux new-session -d -s letterbox-dev
|
||||
tmux rename-window web
|
||||
tmux send-keys "cd web; trunk serve --release --address 0.0.0.0 --port 6758 --proxy-backend http://localhost:9345/ --proxy-rewrite=/api/ -w ../shared -w ../notmuch -w ./" C-m
|
||||
tmux send-keys "cd web; trunk serve -w ../shared -w ../notmuch -w ./" C-m
|
||||
tmux new-window -n server
|
||||
tmux send-keys "cd server; cargo watch -x run -w ../shared -w ../notmuch -w ./" C-m
|
||||
tmux attach -d -t letterbox-dev
|
||||
|
||||
@@ -6,6 +6,8 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.75"
|
||||
clap = { version = "4.4.7", features = ["derive"] }
|
||||
log = "0.4.14"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = { version = "1.0", features = ["unbounded_depth"] }
|
||||
|
||||
@@ -454,6 +454,8 @@ pub enum NotmuchError {
|
||||
SerdeJson(#[from] serde_json::Error),
|
||||
#[error("failed to parse bytes as str")]
|
||||
Utf8Error(#[from] std::str::Utf8Error),
|
||||
#[error("failed to parse bytes as String")]
|
||||
StringUtf8Error(#[from] std::string::FromUtf8Error),
|
||||
#[error("failed to parse str as int")]
|
||||
ParseIntError(#[from] std::num::ParseIntError),
|
||||
}
|
||||
|
||||
46
notmuch/src/main.rs
Normal file
46
notmuch/src/main.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use notmuch::Notmuch;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
#[command(propagate_version = true)]
|
||||
struct Cli {
|
||||
/// Optional notmuch config file
|
||||
#[arg(short, long)]
|
||||
config: Option<PathBuf>,
|
||||
|
||||
#[command(subcommand)]
|
||||
command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
/// Show given search term
|
||||
Show { search_term: String },
|
||||
/// Search for given search term
|
||||
Search { search_term: String },
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
let nm = if let Some(config_path) = cli.config {
|
||||
Notmuch::with_config(config_path)
|
||||
} else {
|
||||
Notmuch::default()
|
||||
};
|
||||
|
||||
// You can check for the existence of subcommands, and if found use their
|
||||
// matches just as you would the top level cmd
|
||||
match &cli.command {
|
||||
Commands::Search { search_term } => {
|
||||
println!("{:#?}", nm.search(&search_term, 0, 10)?);
|
||||
}
|
||||
Commands::Show { search_term } => {
|
||||
println!("{:#?}", nm.show(&search_term)?);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
name = "server"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
default-bin = "server"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -16,6 +17,7 @@ serde = { version = "1.0.147", features = ["derive"] }
|
||||
log = "0.4.17"
|
||||
tokio = "1.26.0"
|
||||
glog = "0.1.0"
|
||||
urlencoding = "2.1.3"
|
||||
|
||||
[dependencies.rocket_contrib]
|
||||
version = "0.4.11"
|
||||
|
||||
@@ -4,7 +4,7 @@ extern crate rocket;
|
||||
use std::{error::Error, io::Cursor, str::FromStr};
|
||||
|
||||
use glog::Flags;
|
||||
use notmuch::{Notmuch, NotmuchError, SearchSummary, ThreadSet};
|
||||
use notmuch::{Notmuch, NotmuchError, ThreadSet};
|
||||
use rocket::{
|
||||
http::{ContentType, Header},
|
||||
request::Request,
|
||||
@@ -13,6 +13,8 @@ use rocket::{
|
||||
Response, State,
|
||||
};
|
||||
use rocket_cors::{AllowedHeaders, AllowedOrigins};
|
||||
use server::{error::ServerError, nm::threadset_to_messages};
|
||||
use shared::Message;
|
||||
|
||||
#[get("/")]
|
||||
fn hello() -> &'static str {
|
||||
@@ -40,13 +42,14 @@ async fn search(
|
||||
) -> Result<Json<shared::SearchResult>, Debug<NotmuchError>> {
|
||||
let page = page.unwrap_or(0);
|
||||
let results_per_page = results_per_page.unwrap_or(10);
|
||||
let query = urlencoding::decode(query).map_err(NotmuchError::from)?;
|
||||
info!(" search '{query}'");
|
||||
let res = shared::SearchResult {
|
||||
summary: nm.search(query, page * results_per_page, results_per_page)?,
|
||||
summary: nm.search(&query, page * results_per_page, results_per_page)?,
|
||||
query: query.to_string(),
|
||||
page,
|
||||
results_per_page,
|
||||
total: nm.count(query)?,
|
||||
total: nm.count(&query)?,
|
||||
};
|
||||
Ok(Json(res))
|
||||
}
|
||||
@@ -55,14 +58,16 @@ async fn search(
|
||||
async fn show_pretty(
|
||||
nm: &State<Notmuch>,
|
||||
query: &str,
|
||||
) -> Result<Json<ThreadSet>, Debug<NotmuchError>> {
|
||||
let res = nm.show(query)?;
|
||||
) -> Result<Json<Vec<Message>>, Debug<ServerError>> {
|
||||
let query = urlencoding::decode(query).map_err(|e| ServerError::from(NotmuchError::from(e)))?;
|
||||
let res = threadset_to_messages(nm.show(&query).map_err(ServerError::from)?)?;
|
||||
Ok(Json(res))
|
||||
}
|
||||
|
||||
#[get("/show/<query>")]
|
||||
async fn show(nm: &State<Notmuch>, query: &str) -> Result<Json<ThreadSet>, Debug<NotmuchError>> {
|
||||
let res = nm.show(query)?;
|
||||
let query = urlencoding::decode(query).map_err(NotmuchError::from)?;
|
||||
let res = nm.show(&query)?;
|
||||
Ok(Json(res))
|
||||
}
|
||||
|
||||
9
server/src/error.rs
Normal file
9
server/src/error.rs
Normal file
@@ -0,0 +1,9 @@
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ServerError {
|
||||
#[error("notmuch")]
|
||||
NotmuchError(#[from] notmuch::NotmuchError),
|
||||
#[error("flatten")]
|
||||
FlattenError,
|
||||
}
|
||||
2
server/src/lib.rs
Normal file
2
server/src/lib.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod error;
|
||||
pub mod nm;
|
||||
15
server/src/nm.rs
Normal file
15
server/src/nm.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use shared::Message;
|
||||
|
||||
use crate::error;
|
||||
|
||||
// TODO(wathiede): decide good error type
|
||||
pub fn threadset_to_messages(
|
||||
thread_set: notmuch::ThreadSet,
|
||||
) -> Result<Vec<Message>, error::ServerError> {
|
||||
for t in thread_set.0 {
|
||||
for tn in t.0 {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
Ok(Vec::new())
|
||||
}
|
||||
@@ -9,3 +9,5 @@ pub struct SearchResult {
|
||||
pub results_per_page: usize,
|
||||
pub total: usize,
|
||||
}
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Message {}
|
||||
|
||||
11
web/Trunk.toml
Normal file
11
web/Trunk.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[build]
|
||||
release = true
|
||||
|
||||
[serve]
|
||||
# The address to serve on.
|
||||
address = "0.0.0.0"
|
||||
port = 6758
|
||||
|
||||
[[proxy]]
|
||||
backend = "http://localhost:9345/"
|
||||
rewrite= "/api/"
|
||||
@@ -4,18 +4,19 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<link rel="modulepreload" href="/pkg/package.js" as="script" type="text/javascript">
|
||||
<link rel="preload" href="/pkg/package_bg.wasm" as="fetch" type="application/wasm" crossorigin="anonymous">
|
||||
<link rel="stylesheet", href="https://jenil.github.io/bulmaswatch/cyborg/bulmaswatch.min.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
<style>
|
||||
.message {
|
||||
padding-left: 0.5em;
|
||||
padding: 0.5em;*/
|
||||
}
|
||||
.body {
|
||||
background: white;
|
||||
color: black;
|
||||
padding-bottom: 1em;
|
||||
padding: 0.5em;
|
||||
margin-left: -0.5em;
|
||||
margin-right: -0.5em;
|
||||
margin-top: 0.5em;
|
||||
}
|
||||
.error {
|
||||
background-color: red;
|
||||
@@ -27,12 +28,24 @@ iframe {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.index {
|
||||
table-layout: fixed;
|
||||
width: 100%;
|
||||
}
|
||||
.index .from {
|
||||
width: 200px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
width: 15em;
|
||||
}
|
||||
.index .subject {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.index .date {
|
||||
width: 8em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.footer {
|
||||
@@ -83,10 +96,6 @@ input::placeholder, .input::placeholder{
|
||||
|
||||
<body>
|
||||
<section id="app"></section>
|
||||
<script type="module">
|
||||
import init from '/pkg/package.js';
|
||||
init('/pkg/package_bg.wasm');
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -22,9 +22,12 @@ const SEARCH_RESULTS_PER_PAGE: usize = 20;
|
||||
|
||||
// `init` describes what should happen when your app started.
|
||||
fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
||||
orders
|
||||
.subscribe(on_url_changed)
|
||||
.notify(subs::UrlChanged(url.clone()));
|
||||
if url.hash().is_none() {
|
||||
orders.request_url(urls::search("is:unread", 0));
|
||||
} else {
|
||||
orders.notify(subs::UrlRequested::new(url));
|
||||
};
|
||||
orders.subscribe(on_url_changed);
|
||||
|
||||
Model {
|
||||
context: Context::None,
|
||||
@@ -94,7 +97,7 @@ mod urls {
|
||||
enum Context {
|
||||
None,
|
||||
Search(shared::SearchResult),
|
||||
Thread(ThreadSet),
|
||||
Thread(Vec<shared::Message>),
|
||||
}
|
||||
|
||||
// `Model` describes our app state.
|
||||
@@ -119,6 +122,9 @@ enum RefreshingState {
|
||||
// `Msg` describes the different events you can modify state with.
|
||||
enum Msg {
|
||||
Noop,
|
||||
// Tell the client to refresh its state
|
||||
Reload,
|
||||
// Tell the server to update state
|
||||
RefreshStart,
|
||||
RefreshDone(Option<FetchError>),
|
||||
SearchRequest {
|
||||
@@ -130,7 +136,7 @@ enum Msg {
|
||||
ShowRequest(String),
|
||||
ShowResult(fetch::Result<ThreadSet>),
|
||||
ShowPrettyRequest(String),
|
||||
ShowPrettyResult(fetch::Result<ThreadSet>),
|
||||
ShowPrettyResult(fetch::Result<Vec<shared::Message>>),
|
||||
NextPage,
|
||||
PreviousPage,
|
||||
}
|
||||
@@ -149,6 +155,10 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
} else {
|
||||
RefreshingState::None
|
||||
};
|
||||
orders.perform_cmd(async move { Msg::Reload });
|
||||
}
|
||||
Msg::Reload => {
|
||||
orders.perform_cmd(async move { on_url_changed(subs::UrlChanged(Url::current())) });
|
||||
}
|
||||
|
||||
Msg::SearchRequest {
|
||||
@@ -175,9 +185,10 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
.skip()
|
||||
.perform_cmd(async move { Msg::ShowResult(show_request(&tid).await) });
|
||||
}
|
||||
// TODO(wathiede): remove
|
||||
Msg::ShowResult(Ok(response_data)) => {
|
||||
debug!("fetch ok {:#?}", response_data);
|
||||
model.context = Context::Thread(response_data);
|
||||
//model.context = Context::Thread(response_data);
|
||||
}
|
||||
Msg::ShowResult(Err(fetch_error)) => {
|
||||
error!("fetch failed {:?}", fetch_error);
|
||||
@@ -189,7 +200,7 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
|
||||
.perform_cmd(async move { Msg::ShowPrettyResult(show_pretty_request(&tid).await) });
|
||||
}
|
||||
Msg::ShowPrettyResult(Ok(response_data)) => {
|
||||
debug!("fetch ok {:#?}", response_data);
|
||||
info!("fetch ok {:#?}", response_data);
|
||||
model.context = Context::Thread(response_data);
|
||||
}
|
||||
Msg::ShowPrettyResult(Err(fetch_error)) => {
|
||||
@@ -278,7 +289,7 @@ async fn show_request(tid: &str) -> fetch::Result<ThreadSet> {
|
||||
.map_err(|_| FetchError::JsonError(fetch::JsonError::Serde(JsValue::NULL)))?)
|
||||
}
|
||||
|
||||
async fn show_pretty_request(tid: &str) -> fetch::Result<ThreadSet> {
|
||||
async fn show_pretty_request(tid: &str) -> fetch::Result<Vec<shared::Message>> {
|
||||
Request::new(api::show_pretty(tid))
|
||||
.method(Method::Get)
|
||||
.fetch()
|
||||
@@ -315,7 +326,6 @@ fn view_message(thread: &ThreadNode) -> Node<Msg> {
|
||||
div![C!["header"], "From: ", &message.headers.from],
|
||||
div![C!["header"], "Date: ", &message.headers.date],
|
||||
div![C!["header"], "To: ", &message.headers.to],
|
||||
hr![],
|
||||
div![
|
||||
C!["body"],
|
||||
match &message.body {
|
||||
@@ -352,7 +362,7 @@ fn view_part(part: &Part) -> Node<Msg> {
|
||||
.build();
|
||||
let inlined = inliner.inline(html).expect("failed to inline CSS");
|
||||
|
||||
return div![C!["view-part-text-html"], div!["TEST"], raw![&inlined]];
|
||||
return div![C!["view-part-text-html"], raw![&inlined]];
|
||||
} else {
|
||||
div![
|
||||
C!["error"],
|
||||
@@ -505,7 +515,6 @@ fn view_mobile_search_results(query: &str, search_results: &shared::SearchResult
|
||||
span![C!["tags"], tags_chiclet(&r.tags, true)],
|
||||
],
|
||||
span![C!["date"], &r.date_relative],
|
||||
hr![],
|
||||
]
|
||||
});
|
||||
let first = search_results.page * search_results.results_per_page;
|
||||
@@ -576,12 +585,8 @@ fn view_search_pager(start: usize, count: usize, total: usize) -> Node<Msg> {
|
||||
nav![
|
||||
C!["pagination"],
|
||||
a![
|
||||
C![
|
||||
"pagination-previous",
|
||||
"button",
|
||||
IF!(is_first => "is-static"),
|
||||
IF!(is_first => "is-info"),
|
||||
],
|
||||
C!["pagination-previous", "button",],
|
||||
IF!(is_first => attrs!{ At::Disabled=>true }),
|
||||
"<",
|
||||
ev(Ev::Click, |_| Msg::PreviousPage)
|
||||
],
|
||||
@@ -598,26 +603,32 @@ fn view_search_pager(start: usize, count: usize, total: usize) -> Node<Msg> {
|
||||
]
|
||||
}
|
||||
|
||||
fn view_thread(thread_set: &ThreadSet) -> Node<Msg> {
|
||||
assert_eq!(thread_set.0.len(), 1);
|
||||
let thread = &thread_set.0[0];
|
||||
assert_eq!(thread.0.len(), 1);
|
||||
let thread_node = &thread.0[0];
|
||||
let subject = first_subject(&thread_node).unwrap_or("<No subject>".to_string());
|
||||
set_title(&subject);
|
||||
fn view_thread(messages: &[shared::Message]) -> Node<Msg> {
|
||||
div!["TODO(wathiede): view_thread(messages)"]
|
||||
/*
|
||||
assert_eq!(thread_set.0.len(), 1);
|
||||
let thread = &thread_set.0[0];
|
||||
assert_eq!(thread.0.len(), 1);
|
||||
let thread_node = &thread.0[0];
|
||||
let subject = first_subject(&thread_node).unwrap_or("<No subject>".to_string());
|
||||
set_title(&subject);
|
||||
div![
|
||||
C!["container"],
|
||||
h1![C!["title"], subject],
|
||||
view_message(&thread_node),
|
||||
a![
|
||||
attrs! {At::Href=>api::original(&thread_node.0.as_ref().expect("message missing").id)},
|
||||
"Original"
|
||||
],
|
||||
/*
|
||||
div![
|
||||
h1![subject],
|
||||
a![
|
||||
attrs! {At::Href=>api::original(&thread_node.0.as_ref().expect("message missing").id)},
|
||||
"Original"
|
||||
],
|
||||
view_message(&thread_node),
|
||||
div![
|
||||
C!["debug"],
|
||||
"Add zippy for debug dump",
|
||||
view_debug_thread_set(thread_set)
|
||||
] /* pre![format!("Thread: {:#?}", thread_set).replace(" ", " ")] */
|
||||
C!["debug"],
|
||||
"Add zippy for debug dump",
|
||||
view_debug_thread_set(thread_set)
|
||||
] /* pre![format!("Thread: {:#?}", thread_set).replace(" ", " ")] */
|
||||
*/
|
||||
]
|
||||
*/
|
||||
}
|
||||
|
||||
fn view_debug_thread_set(thread_set: &ThreadSet) -> Node<Msg> {
|
||||
@@ -725,24 +736,26 @@ fn view_footer(render_time_ms: u128) -> Node<Msg> {
|
||||
fn view_desktop(model: &Model) -> Node<Msg> {
|
||||
let content = match &model.context {
|
||||
Context::None => div![h1!["Loading"]],
|
||||
Context::Thread(thread_set) => view_thread(thread_set),
|
||||
Context::Thread(messages) => view_thread(messages),
|
||||
Context::Search(search_results) => view_search_results(&model.query, search_results),
|
||||
};
|
||||
div![
|
||||
view_header(&model.query, &model.refreshing_state),
|
||||
section![C!["section"], div![C!["container"], content],]
|
||||
section![C!["section"], content],
|
||||
view_header(&model.query, &model.refreshing_state),
|
||||
]
|
||||
}
|
||||
|
||||
fn view_mobile(model: &Model) -> Node<Msg> {
|
||||
let content = match &model.context {
|
||||
Context::None => div![h1!["Loading"]],
|
||||
Context::Thread(thread_set) => view_thread(thread_set),
|
||||
Context::Thread(messages) => view_thread(messages),
|
||||
Context::Search(search_results) => view_mobile_search_results(&model.query, search_results),
|
||||
};
|
||||
div![
|
||||
view_header(&model.query, &model.refreshing_state),
|
||||
section![C!["section"], div![C!["content"], content],]
|
||||
section![C!["section"], div![C!["content"], content]],
|
||||
view_header(&model.query, &model.refreshing_state),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user