diff --git a/smart-house-web/frontend/src/main.rs b/smart-house-web/frontend/src/main.rs index be163b3..da7fc9a 100644 --- a/smart-house-web/frontend/src/main.rs +++ b/smart-house-web/frontend/src/main.rs @@ -1,100 +1,88 @@ #![allow(non_snake_case)] -use leptos::ev::SubmitEvent; use leptos::prelude::*; #[component] fn App() -> impl IntoView { - view! { -
"Value is: " {value}
+ +"Option" {odd_text}
+ // This means you can use `Option` methods on it +{move || odd_text().map(|text| text.len())}
+ ++ {move || if is_odd() { + "Odd" + } else { + "Even" + }} +
+ + // b. Toggling some kind of class + // This is smart for an element that's going to + // toggled often, because it doesn't destroy + // it in between states + // (you can find the `hidden` class in `index.html`) +"Appears if even."
+ + // c. The"Oddment"
+"Oddity!"
})} + + returns HtmlElement
+ view! { "One"
}.into_any()
+ },
+ false if value.get() == 2 => {
+ // returns HtmlElement
+ // so we convert into a more generic type
+ view! {
"Two"
}.into_any()
}
-
- // the `prop:` syntax lets you update a DOM property,
- // rather than an attribute.
- //
- // IMPORTANT: the `value` *attribute* only sets the
- // initial value, until you have made a change.
- // The `value` *property* sets the current value.
- // This is a quirk of the DOM; I didn't invent it.
- // Other frameworks gloss this over; I think it's
- // more important to give you access to the browser
- // as it really works.
- //
- // tl;dr: use prop:value for form inputs
- prop:value=name
- />
- "Name is: " {name}
+ _ => view! { }.into_any()
+ }}
}
}
-#[component]
-fn UncontrolledComponent() -> impl IntoView {
- // import the type for
- use leptos::html::Input;
-
- let (name, set_name) = signal("Uncontrolled".to_string());
-
- // we'll use a NodeRef to store a reference to the input element
- // this will be filled when the element is created
- let input_element: NodeRef = NodeRef::new();
-
- // fires when the form `submit` event happens
- // this will store the value of the in our signal
- let on_submit = move |ev: SubmitEvent| {
- // stop the page from reloading!
- ev.prevent_default();
-
- // here, we'll extract the value from the input
- let value = input_element
- .get()
- // event handlers can only fire after the view
- // is mounted to the DOM, so the `NodeRef` will be `Some`
- .expect(" to exist")
- // `NodeRef` implements `Deref` for the DOM element type
- // this means we can call`HtmlInputElement::value()`
- // to get the current value of the input
- .value();
- set_name.set(value);
- };
-
- view! {
-
- "Name is: " {name}
- } -} - -// This `main` function is the entry point into the app -// It just mounts our component to the -// Because we defined it as `fn App`, we can now use it in a -// template as