mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-25 13:40:19 +00:00
20d146d9bd
* improve documentation for the fullstack server context * Add a section about axum integration to the crate root docs * make serve_dioxus_application accept the cfg builder directly * remove unused server_fn module * improve fullstack config docs * improve documentation for the server function macro * fix axum router extension link * Fix doc tests * Fix launch builder * Simplify the launch builder * don't re-export launch in the prelude * refactor fullstack launch * Fix fullstack launch builder * Update static generation with the new builder api * fix some formatting/overly broad launch replacements * fix custom menu example * fix fullstack/static generation examples * Fix static generation launch * A few small formatting fixes * Fix a few doc tests * implement LaunchConfig for serve configs * fix fullstack launch with separate web and server launch methods * fix check with all features * dont expose inner core module * clippy and check * fix readme --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
60 lines
1.8 KiB
Rust
60 lines
1.8 KiB
Rust
//! This example shows how to create a popup window and send data back to the parent window.
|
|
//! Currently Dioxus doesn't support nested renderers, hence the need to create popups as separate windows.
|
|
|
|
use dioxus::prelude::*;
|
|
use std::rc::Rc;
|
|
|
|
fn main() {
|
|
dioxus::LaunchBuilder::desktop().launch(app);
|
|
}
|
|
|
|
fn app() -> Element {
|
|
let mut emails_sent = use_signal(|| Vec::new() as Vec<String>);
|
|
|
|
// Wait for responses to the compose channel, and then push them to the emails_sent signal.
|
|
let handle = use_coroutine(move |mut rx: UnboundedReceiver<String>| async move {
|
|
use futures_util::StreamExt;
|
|
while let Some(message) = rx.next().await {
|
|
emails_sent.write().push(message);
|
|
}
|
|
});
|
|
|
|
let open_compose_window = move |_evt: MouseEvent| {
|
|
let tx = handle.tx();
|
|
dioxus::desktop::window().new_window(
|
|
VirtualDom::new_with_props(popup, Rc::new(move |s| tx.unbounded_send(s).unwrap())),
|
|
Default::default(),
|
|
);
|
|
};
|
|
|
|
rsx! {
|
|
h1 { "This is your email" }
|
|
button { onclick: open_compose_window, "Click to compose a new email" }
|
|
ul {
|
|
for message in emails_sent.read().iter() {
|
|
li {
|
|
h3 { "email" }
|
|
span { "{message}" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fn popup(send: Rc<dyn Fn(String)>) -> Element {
|
|
let mut user_input = use_signal(String::new);
|
|
|
|
rsx! {
|
|
div {
|
|
h1 { "Compose a new email" }
|
|
button {
|
|
onclick: move |_| {
|
|
send(user_input.cloned());
|
|
dioxus::desktop::window().close();
|
|
},
|
|
"Send"
|
|
}
|
|
input { oninput: move |e| user_input.set(e.value()), value: "{user_input}" }
|
|
}
|
|
}
|
|
}
|