feat: event handling on desktop

This commit is contained in:
Jonathan Kelley committed 2022-11-17 20:00:39 -08:00
1 parent 073fea9ed3
commit 30ef225812
29 files changed
+424 -205

No files matched your search

+9 -17
View File
@@ -1,7 +1,3 @@
#![allow(non_snake_case)]
//! Render a bunch of doggos!
use dioxus::prelude::*;
use std::collections::HashMap;
@@ -19,8 +15,8 @@ struct ListBreeds {
}
async fn app_root(cx: Scope<'_>) -> Element {
let breed = use_state(&cx, || "deerhound".to_string());
let breeds = use_future(&cx, (), |_| async move {
let breed = use_state(cx, || "deerhound".to_string());
let breeds = use_future!(cx, || async move {
reqwest::get("https://dog.ceo/api/breeds/list/all")
.await
.unwrap()
@@ -45,7 +41,9 @@ async fn app_root(cx: Scope<'_>) -> Element {
}
}
}
div { flex: "50%", Breed { breed: breed.to_string() } }
div { flex: "50%",
breed_pic { breed: breed.to_string() }
}
}
}
}),
@@ -59,10 +57,8 @@ struct DogApi {
}
#[inline_props]
async fn Breed(cx: Scope, breed: String) -> Element {
println!("Rendering Breed: {}", breed);
let fut = use_future(&cx, (breed,), |(breed,)| async move {
async fn breed_pic(cx: Scope, breed: String) -> Element {
let fut = use_future!(cx, |breed| async move {
reqwest::get(format!("https://dog.ceo/api/breed/{}/images/random", breed))
.await
.unwrap()
@@ -70,11 +66,7 @@ async fn Breed(cx: Scope, breed: String) -> Element {
.await
});
let resp = fut.await;
println!("achieved results!");
match resp {
match fut.await {
Ok(resp) => cx.render(rsx! {
div {
button {
@@ -88,6 +80,6 @@ async fn Breed(cx: Scope, breed: String) -> Element {
}
}
}),
Err(e) => cx.render(rsx! { div { "loading dogs failed" } }),
Err(_) => cx.render(rsx! { div { "loading dogs failed" } }),
}
}
+2 -8
View File
@@ -1,5 +1,3 @@
use std::fmt::Display;
use dioxus::prelude::*;
fn main() {
@@ -7,13 +5,9 @@ fn main() {
}
fn app(cx: Scope) -> Element {
cx.render(rsx! {
generic_child::<i32>{}
})
cx.render(rsx! { generic_child::<i32>{} })
}
fn generic_child<T>(cx: Scope) -> Element {
cx.render(rsx! {
div {}
})
cx.render(rsx! { div {} })
}
+2 -5
View File
@@ -2,7 +2,6 @@
//!
//! There is some conversion happening when input types are checkbox/radio/select/textarea etc.
use dioxus::events::FormData;
use dioxus::prelude::*;
fn main() {
@@ -29,7 +28,6 @@ const FIELDS: &[(&str, &str)] = &[
("text", ""),
("time", ""),
("url", ""),
//
// less supported things
("hidden", ""),
("month", ""), // degrades to text most of the time, but works properly as "value'"
@@ -115,7 +113,7 @@ fn app(cx: Scope) -> Element {
}
}
FIELDS.iter().map(|(field, value)| rsx!(
FIELDS.iter().map(|(field, value)| rsx! {
div {
input {
id: "{field}",
@@ -132,8 +130,7 @@ fn app(cx: Scope) -> Element {
}
br {}
}
))
})
}
})
}