2022-12-31 17:19:21 +00:00
|
|
|
//! This example shows how to create a popup window and send data back to the parent window.
|
|
|
|
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
use futures_util::StreamExt;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
dioxus_desktop::launch(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn app(cx: Scope) -> Element {
|
2023-01-12 00:13:41 +00:00
|
|
|
let emails_sent = use_ref(cx, Vec::new);
|
2022-12-31 17:19:21 +00:00
|
|
|
|
|
|
|
let tx = use_coroutine(cx, |mut rx: UnboundedReceiver<String>| {
|
|
|
|
to_owned![emails_sent];
|
|
|
|
async move {
|
|
|
|
while let Some(message) = rx.next().await {
|
|
|
|
emails_sent.write().push(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
h1 { "This is your email" }
|
|
|
|
|
|
|
|
button {
|
|
|
|
onclick: move |_| {
|
2023-12-11 22:01:40 +00:00
|
|
|
let dom = VirtualDom::new_with_props(compose, ComposeProps { app_tx: tx.clone() });
|
2024-01-05 01:08:06 +00:00
|
|
|
dioxus_desktop::window().new_window(dom, Default::default());
|
2022-12-31 17:19:21 +00:00
|
|
|
},
|
|
|
|
"Click to compose a new email"
|
|
|
|
}
|
|
|
|
|
|
|
|
ul {
|
2024-01-11 03:33:34 +00:00
|
|
|
for message in emails_sent.read().iter() {
|
2022-12-31 17:19:21 +00:00
|
|
|
li {
|
|
|
|
h3 { "email" }
|
|
|
|
span {"{message}"}
|
|
|
|
}
|
2024-01-11 03:33:34 +00:00
|
|
|
}
|
2022-12-31 17:19:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ComposeProps {
|
|
|
|
app_tx: Coroutine<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn compose(cx: Scope<ComposeProps>) -> Element {
|
2023-01-12 00:13:41 +00:00
|
|
|
let user_input = use_state(cx, String::new);
|
2022-12-31 17:19:21 +00:00
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
h1 { "Compose a new email" }
|
|
|
|
|
|
|
|
button {
|
|
|
|
onclick: move |_| {
|
|
|
|
cx.props.app_tx.send(user_input.get().clone());
|
2023-10-23 20:26:10 +00:00
|
|
|
dioxus_desktop::window().close();
|
2022-12-31 17:19:21 +00:00
|
|
|
},
|
|
|
|
"Click to send"
|
|
|
|
}
|
2024-01-06 07:15:30 +00:00
|
|
|
|
2024-01-05 01:02:00 +00:00
|
|
|
input { oninput: move |e| user_input.set(e.value()), value: "{user_input}" }
|
2022-12-31 17:19:21 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|