feat: it loads the doggos
This commit is contained in:
1 parent
3a57b94262
commit
abf47596bc
2 files changed
+31
-11
No files matched your search
@@ -78,4 +78,8 @@ separator = "0.4.1"
|
|||||||
uuid = { version = "0.8.2", features = ["v4", "wasm-bindgen"] }
|
uuid = { version = "0.8.2", features = ["v4", "wasm-bindgen"] }
|
||||||
dioxus-hooks = { path = "../hooks" }
|
dioxus-hooks = { path = "../hooks" }
|
||||||
gloo-timers = { version = "0.2.1", features = ["futures"] }
|
gloo-timers = { version = "0.2.1", features = ["futures"] }
|
||||||
|
serde = { version = "1.0.126", features = ["derive"] }
|
||||||
|
surf = { version = "2.2.0", default-features = false, features = [
|
||||||
|
"wasm-client",
|
||||||
|
] }
|
||||||
# wasm-timer = "0.2.5"
|
# wasm-timer = "0.2.5"
|
||||||
@@ -17,13 +17,20 @@ use dioxus_web::*;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Setup logging
|
// Setup logging
|
||||||
wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
// wasm_logger::init(wasm_logger::Config::new(log::Level::Debug));
|
||||||
console_error_panic_hook::set_once();
|
console_error_panic_hook::set_once();
|
||||||
|
|
||||||
// Run the app
|
// Run the app
|
||||||
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(App));
|
wasm_bindgen_futures::spawn_local(WebsysRenderer::start(App));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct DogApi {
|
||||||
|
message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
const ENDPOINT: &str = "https://dog.ceo/api/breeds/image/random/";
|
||||||
|
|
||||||
static App: FC<()> = |cx| {
|
static App: FC<()> = |cx| {
|
||||||
// let mut count = use_state(cx, || 0);
|
// let mut count = use_state(cx, || 0);
|
||||||
let state = use_state(cx, || 0);
|
let state = use_state(cx, || 0);
|
||||||
@@ -32,19 +39,24 @@ static App: FC<()> = |cx| {
|
|||||||
let g = cx.use_task(|| async move {
|
let g = cx.use_task(|| async move {
|
||||||
let mut tick: i32 = 0;
|
let mut tick: i32 = 0;
|
||||||
log::debug!("yeet!");
|
log::debug!("yeet!");
|
||||||
loop {
|
// loop {
|
||||||
gloo_timers::future::TimeoutFuture::new(250).await;
|
// gloo_timers::future::TimeoutFuture::new(250).await;
|
||||||
log::debug!("ticking forward... {}", tick);
|
// log::debug!("ticking forward... {}", tick);
|
||||||
tick += 1;
|
// tick += 1;
|
||||||
if tick > 10 {
|
// if tick > 10 {
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
set_val(10);
|
set_val(10);
|
||||||
String::from("Huzza!")
|
surf::get(ENDPOINT).recv_json::<DogApi>().await
|
||||||
|
// String::from("Huzza!")
|
||||||
});
|
});
|
||||||
|
|
||||||
log::debug!("Value from component was {:#?}", g);
|
let dog_node = match g.as_ref().and_then(|f| f.as_ref().ok()) {
|
||||||
|
Some(res) => rsx!(in cx, img { src: "{res.message}" }),
|
||||||
|
None => rsx!(in cx, div { "No doggos for you :(" }),
|
||||||
|
};
|
||||||
|
|
||||||
cx.render(rsx! {
|
cx.render(rsx! {
|
||||||
div {
|
div {
|
||||||
@@ -65,6 +77,10 @@ static App: FC<()> = |cx| {
|
|||||||
"decr"
|
"decr"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
div {
|
||||||
|
h1{"doggo!"}
|
||||||
|
{dog_node}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user