From da65106c7e828143273cd6c58c7a9533120f3f0c Mon Sep 17 00:00:00 2001 From: Ryan Khetlyr Date: Thu, 28 Nov 2024 14:48:01 -0800 Subject: [PATCH] hide form when name exists --- src/main.rs | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index b71bd06..a99fa43 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,16 +6,19 @@ use web_sys::MouseEvent; fn App() -> impl IntoView { let (name, set_name) = signal(String::new()); let (greeting, set_greeting) = signal(String::new()); + let (show_form, set_show_form) = signal(true); let handle_submit = move |_: MouseEvent| { if !name.get().is_empty() { set_greeting.set(format!("Hello, {}!", name.get())); + set_show_form.set(false); } }; let handle_keypress = move |ev: web_sys::KeyboardEvent| { if ev.key() == "Enter" && !name.get().is_empty() { set_greeting.set(format!("Hello, {}!", name.get())); + set_show_form.set(false); } }; @@ -28,21 +31,25 @@ fn App() -> impl IntoView { greeting.get() }} - - + {move || show_form.get().then(|| view! { + <> + + + + })} } }