web: prototype websocket client

This commit is contained in:
Bill Thiede 2025-04-14 10:32:17 -07:00
parent b11f6b5149
commit 638d55a36c
4 changed files with 26 additions and 1 deletions

14
Cargo.lock generated
View File

@ -3097,6 +3097,7 @@ dependencies = [
"uuid",
"wasm-bindgen",
"wasm-bindgen-test",
"wasm-sockets",
"web-sys",
]
@ -7303,6 +7304,19 @@ dependencies = [
"syn 2.0.100",
]
[[package]]
name = "wasm-sockets"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d14bbe65995269301ab677e5d69b3b69195447c01137ef44f72b10eecea55c77"
dependencies = [
"js-sys",
"log",
"thiserror 1.0.69",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "web-sys"
version = "0.3.77"

View File

@ -37,6 +37,7 @@ letterbox-shared = { version = "0.12.1", path = "../shared", registry = "xinu" }
letterbox-notmuch = { version = "0.12.1", path = "../notmuch", registry = "xinu" }
seed_hooks = { version = "0.4.0", registry = "xinu" }
strum_macros = "0.27.1"
wasm-sockets = "1.0.0"
[package.metadata.wasm-pack.profile.release]
wasm-opt = ['-Os']

View File

@ -11,6 +11,7 @@ mod consts;
mod graphql;
mod state;
mod view;
mod websocket;
fn main() {
// This provides better error messages in debug mode.

View File

@ -11,6 +11,7 @@ use crate::{
consts::SEARCH_RESULTS_PER_PAGE,
graphql,
graphql::{front_page_query::*, send_graphql, show_thread_query::*},
websocket,
};
/// Used to fake the unread string while in development
@ -38,7 +39,7 @@ pub fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
if url.hash().is_none() {
orders.request_url(urls::search(unread_query(), 0));
} else {
orders.request_url(url);
orders.request_url(url.clone());
};
// TODO(wathiede): only do this while viewing the index? Or maybe add a new message that force
// 'notmuch new' on the server periodically?
@ -60,6 +61,7 @@ pub fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
},
catchup: None,
last_url: Url::current(),
websocket: websocket::init(url, &mut orders.proxy(Msg::WebSocket)),
}
}
@ -659,6 +661,10 @@ pub fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
orders.send_msg(Msg::ScrollToTop);
model.catchup = None;
}
Msg::WebSocket(ws) => {
websocket::update(ws, &mut model.websocket, &mut orders.proxy(Msg::WebSocket))
}
}
}
@ -691,6 +697,7 @@ pub struct Model {
pub versions: Version,
pub catchup: Option<Catchup>,
pub last_url: Url,
pub websocket: websocket::Model,
}
#[derive(Debug)]
@ -822,4 +829,6 @@ pub enum Msg {
CatchupMarkAsRead,
CatchupNext,
CatchupExit,
WebSocket(websocket::Msg),
}