This commit is contained in:
2024-08-31 00:58:39 -06:00
parent 5a48d0bcf7
commit e19333d686
5 changed files with 302 additions and 214 deletions
+41 -5
View File
@@ -2,23 +2,59 @@
use dioxus::prelude::*;
use super::Command;
use super::Command::*;
use super::ConnectionState::{self, *};
pub struct State {
pub status: GlobalSignal<String>,
pub status: GlobalSignal<ConnectionState>,
}
pub static STATE: State = State {
status: Signal::global(|| "Starting...".to_owned()),
status: Signal::global(|| Disconnected),
};
pub fn app() -> Element {
use_coroutine(|_: UnboundedReceiver<()>| super::network_entrypoint());
let net = use_coroutine(|rx: UnboundedReceiver<Command>| super::network_entrypoint(rx));
let mut username = use_signal(|| "".to_string());
let default_address = option_env!("MUMBLEWEB2_WEBTRANSPORT_SERVER_ADDRESS").unwrap_or("");
let mut address = use_signal(|| default_address.to_string());
let status = &STATE.status;
rsx!(
div {
"Hello, World!"
input {
placeholder: "username",
value: "{username.read()}",
autofocus: "true",
oninput: move |evt| username.set(evt.value().clone()),
}
br {}
input {
placeholder: "server address",
value: "{address.read()}",
autofocus: "true",
oninput: move |evt| address.set(evt.value().clone()),
}
br {}
match *status.read() {
Disconnected => rsx!{
button {
onclick: move |event| net.send(Connect{address: address.read().clone(), username: username.read().clone(), hash: "[39, 96, 204, 127, 26, 59, 35, 209, 197, 103, 192, 6, 3, 98, 203, 228, 124, 46, 247, 72, 44, 224, 123, 238, 218, 140, 128, 100, 115, 14, 23, 233]".to_string()}),
"Connect!"
}
},
Connecting => rsx!{
"Connecting..."
},
Connected => rsx!{
button {
onclick: move |event| net.send(Disconnect),
"Disconnect"
}
}
}
br {}
"{status}"
}
)
}