wip: some ideas
This commit is contained in:
1 parent
583fdfa561
commit
05c909f320
21 files changed
+662
-1112
No files matched your search
+23
-25
@@ -2,43 +2,41 @@
|
||||
//!
|
||||
//! The example from the README.md
|
||||
|
||||
use std::{pin::Pin, time::Duration};
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use futures::Future;
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
log::info!("hello world");
|
||||
dioxus::desktop::launch(App, |c| c).expect("faield to launch");
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
struct DogApi {
|
||||
message: String,
|
||||
}
|
||||
pub static App: FC<()> = |cx| {
|
||||
let count = use_state(cx, || 0);
|
||||
let mut direction = use_state(cx, || 1);
|
||||
|
||||
const ENDPOINT: &str = "https://dog.ceo/api/breeds/image/random";
|
||||
|
||||
static App: FC<()> = |cx| {
|
||||
let mut count = use_state(cx, || 0);
|
||||
let mut fut = Box::pin(async {
|
||||
let mut tick: i32 = 0;
|
||||
let (async_count, dir) = (count.for_async(), *direction);
|
||||
let (task, _result) = cx.use_task(move || async move {
|
||||
loop {
|
||||
async_std::task::sleep(Duration::from_millis(250)).await;
|
||||
log::debug!("ticking forward... {}", tick);
|
||||
tick += 1;
|
||||
// match surf::get(ENDPOINT).recv_json::<DogApi>().await {
|
||||
// Ok(_) => (),
|
||||
// Err(_) => (),
|
||||
// }
|
||||
gloo_timers::future::TimeoutFuture::new(250).await;
|
||||
*async_count.get_mut() += dir;
|
||||
}
|
||||
});
|
||||
|
||||
cx.submit_task(fut);
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
h1 {"it's working somewhat properly"}
|
||||
h1 {"count is {count}"}
|
||||
button {
|
||||
"Stop counting"
|
||||
onclick: move |_| task.stop()
|
||||
}
|
||||
button {
|
||||
"Start counting"
|
||||
onclick: move |_| task.start()
|
||||
}
|
||||
button {
|
||||
"Switch counting direcion"
|
||||
onclick: move |_| {
|
||||
direction *= -1;
|
||||
task.restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
Reference in new issue
Block a user