2021-05-26 05:40:30 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use dioxus_core::prelude::*;
|
|
|
|
use recoil::*;
|
2021-05-26 15:22:44 +00:00
|
|
|
use uuid::Uuid;
|
2021-05-26 05:40:30 +00:00
|
|
|
|
2021-05-26 15:22:44 +00:00
|
|
|
const TODOS: AtomFamily<Uuid, Todo> = |_| HashMap::new();
|
2021-05-26 05:40:30 +00:00
|
|
|
|
|
|
|
#[derive(PartialEq)]
|
|
|
|
struct Todo {
|
|
|
|
checked: bool,
|
2021-05-26 15:22:44 +00:00
|
|
|
title: String,
|
2021-05-26 05:40:30 +00:00
|
|
|
contents: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
static App: FC<()> = |ctx, _| {
|
2021-05-26 15:22:44 +00:00
|
|
|
use_init_recoil_root(ctx);
|
|
|
|
|
|
|
|
let todos = use_recoil_family(ctx, &TODOS);
|
|
|
|
|
2021-05-26 05:40:30 +00:00
|
|
|
rsx! { in ctx,
|
|
|
|
div {
|
|
|
|
"Basic Todolist with AtomFamilies in Recoil.rs"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-26 15:22:44 +00:00
|
|
|
#[derive(Props, PartialEq)]
|
|
|
|
struct ChildProps {
|
|
|
|
id: Uuid,
|
|
|
|
}
|
|
|
|
|
|
|
|
static Child: FC<ChildProps> = |ctx, props| {
|
|
|
|
let (todo, set_todo) = use_recoil_state(ctx, &TODOS.select(&props.id));
|
|
|
|
|
2021-05-26 05:40:30 +00:00
|
|
|
rsx! { in ctx,
|
|
|
|
div {
|
2021-05-26 15:22:44 +00:00
|
|
|
h1 {"{todo.title}"}
|
|
|
|
input { type: "checkbox", name: "scales", checked: "{todo.checked}" }
|
|
|
|
label { "{todo.contents}", for: "scales" }
|
|
|
|
p {"{todo.contents}"}
|
2021-05-26 05:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
|
|
|
|
}
|