web: prototype websocket client
This commit is contained in:
parent
b11f6b5149
commit
638d55a36c
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -3097,6 +3097,7 @@ dependencies = [
|
|||||||
"uuid",
|
"uuid",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"wasm-bindgen-test",
|
"wasm-bindgen-test",
|
||||||
|
"wasm-sockets",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -7303,6 +7304,19 @@ dependencies = [
|
|||||||
"syn 2.0.100",
|
"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]]
|
[[package]]
|
||||||
name = "web-sys"
|
name = "web-sys"
|
||||||
version = "0.3.77"
|
version = "0.3.77"
|
||||||
|
|||||||
@ -37,6 +37,7 @@ letterbox-shared = { version = "0.12.1", path = "../shared", registry = "xinu" }
|
|||||||
letterbox-notmuch = { version = "0.12.1", path = "../notmuch", registry = "xinu" }
|
letterbox-notmuch = { version = "0.12.1", path = "../notmuch", registry = "xinu" }
|
||||||
seed_hooks = { version = "0.4.0", registry = "xinu" }
|
seed_hooks = { version = "0.4.0", registry = "xinu" }
|
||||||
strum_macros = "0.27.1"
|
strum_macros = "0.27.1"
|
||||||
|
wasm-sockets = "1.0.0"
|
||||||
|
|
||||||
[package.metadata.wasm-pack.profile.release]
|
[package.metadata.wasm-pack.profile.release]
|
||||||
wasm-opt = ['-Os']
|
wasm-opt = ['-Os']
|
||||||
|
|||||||
@ -11,6 +11,7 @@ mod consts;
|
|||||||
mod graphql;
|
mod graphql;
|
||||||
mod state;
|
mod state;
|
||||||
mod view;
|
mod view;
|
||||||
|
mod websocket;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// This provides better error messages in debug mode.
|
// This provides better error messages in debug mode.
|
||||||
|
|||||||
@ -11,6 +11,7 @@ use crate::{
|
|||||||
consts::SEARCH_RESULTS_PER_PAGE,
|
consts::SEARCH_RESULTS_PER_PAGE,
|
||||||
graphql,
|
graphql,
|
||||||
graphql::{front_page_query::*, send_graphql, show_thread_query::*},
|
graphql::{front_page_query::*, send_graphql, show_thread_query::*},
|
||||||
|
websocket,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Used to fake the unread string while in development
|
/// 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() {
|
if url.hash().is_none() {
|
||||||
orders.request_url(urls::search(unread_query(), 0));
|
orders.request_url(urls::search(unread_query(), 0));
|
||||||
} else {
|
} 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
|
// TODO(wathiede): only do this while viewing the index? Or maybe add a new message that force
|
||||||
// 'notmuch new' on the server periodically?
|
// 'notmuch new' on the server periodically?
|
||||||
@ -60,6 +61,7 @@ pub fn init(url: Url, orders: &mut impl Orders<Msg>) -> Model {
|
|||||||
},
|
},
|
||||||
catchup: None,
|
catchup: None,
|
||||||
last_url: Url::current(),
|
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);
|
orders.send_msg(Msg::ScrollToTop);
|
||||||
model.catchup = None;
|
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 versions: Version,
|
||||||
pub catchup: Option<Catchup>,
|
pub catchup: Option<Catchup>,
|
||||||
pub last_url: Url,
|
pub last_url: Url,
|
||||||
|
pub websocket: websocket::Model,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -822,4 +829,6 @@ pub enum Msg {
|
|||||||
CatchupMarkAsRead,
|
CatchupMarkAsRead,
|
||||||
CatchupNext,
|
CatchupNext,
|
||||||
CatchupExit,
|
CatchupExit,
|
||||||
|
|
||||||
|
WebSocket(websocket::Msg),
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user