basic dioxus state

This commit is contained in:
2024-05-21 21:38:40 -04:00
parent 7fb6e95c79
commit a2239cfe7e
5 changed files with 23 additions and 2 deletions
Generated
+1
View File
@@ -1525,6 +1525,7 @@ dependencies = [
"dioxus",
"dioxus-web",
"manganis",
"once_cell",
"serde-wasm-bindgen 0.6.5",
"serde_json",
"wasm-bindgen",
+1
View File
@@ -7,6 +7,7 @@ edition = "2021"
dioxus = { version = "0.5.1", features = ["web"] }
dioxus-web = "0.5.1"
manganis = "0.2.2"
once_cell = "1.19.0"
serde-wasm-bindgen = "0.6.5"
serde_json = "1.0.117"
wasm-bindgen = "0.2.92"
+13
View File
@@ -2,10 +2,23 @@
use dioxus::prelude::*;
pub struct State {
pub status: GlobalSignal<String>,
}
pub static STATE: State = State {
status: Signal::global(|| "Starting...".to_owned()),
};
pub fn app() -> Element {
use_coroutine(|_: UnboundedReceiver<()>| super::network_entrypoint());
let status = &STATE.status;
rsx!(
div {
"Hello, World!"
br {}
"{status}"
}
)
}
+7
View File
@@ -1,5 +1,6 @@
pub mod app;
use app::STATE;
use wasm_bindgen::prelude::*;
use web_sys::console;
use web_sys::WebTransport;
@@ -42,6 +43,8 @@ pub async fn network_entrypoint() {
console::log_1(&"Created WebTransportOptions!".into());
*STATE.status.write() = "Connecting to WebTransport...".into();
let transport = match WebTransport::new_with_options(
"https://localhost:4433/?hostname=ohea.xyz&port=64738&username=test",
&options,
@@ -64,6 +67,8 @@ pub async fn network_entrypoint() {
console::log_1(&"Transport is ready.".into());
*STATE.status.write() = "Creating stream...".into();
let stream: web_sys::WebTransportBidirectionalStream =
match wasm_bindgen_futures::JsFuture::from(transport.create_bidirectional_stream()).await {
Ok(x) => x.into(),
@@ -78,4 +83,6 @@ pub async fn network_entrypoint() {
console::log_1(&"Created bidirectional stream!".into());
console::log_1(&stream.into());
//*STATE.status.write() = "Ready!".into();
}
+1 -2
View File
@@ -1,6 +1,5 @@
use mumble_webtransport::{app, network_entrypoint};
use mumble_webtransport::app;
pub fn main() {
wasm_bindgen_futures::spawn_local(network_entrypoint());
dioxus::launch(app::app);
}