2021-05-31 22:55:56 +00:00
|
|
|
use std::{collections::HashMap, rc::Rc};
|
2021-05-26 05:40:30 +00:00
|
|
|
|
|
|
|
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-31 22:55:56 +00:00
|
|
|
const TODOS: AtomHashMap<Uuid, Rc<Todo>> = |map| {};
|
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-31 22:55:56 +00:00
|
|
|
content: String,
|
2021-05-26 05:40:30 +00:00
|
|
|
}
|
|
|
|
|
2021-06-26 01:15:33 +00:00
|
|
|
static App: FC<()> = |cx| {
|
|
|
|
use_init_recoil_root(cx, move |cfg| {});
|
2021-05-31 22:55:56 +00:00
|
|
|
|
2021-06-26 01:15:33 +00:00
|
|
|
let todos = use_read_family(cx, &TODOS);
|
2021-05-26 15:22:44 +00:00
|
|
|
|
2021-06-26 01:15:33 +00:00
|
|
|
// rsx! { in cx,
|
2021-05-31 22:55:56 +00:00
|
|
|
// div {
|
|
|
|
// h1 {"Basic Todolist with AtomFamilies in Recoil.rs"}
|
|
|
|
// ul { { todos.keys().map(|id| rsx! { Child { id: *id } }) } }
|
|
|
|
// }
|
|
|
|
// }
|
2021-06-26 01:15:33 +00:00
|
|
|
cx.render(html! {
|
2021-05-31 22:55:56 +00:00
|
|
|
<a href="#" class="">
|
|
|
|
<img class="inline-block h-10 w-10 rounded-full object-cover ring-2 ring-white" src="/images/person/4.jpg" alt="Jade"/>
|
|
|
|
</a>
|
|
|
|
})
|
2021-05-26 05:40:30 +00:00
|
|
|
};
|
|
|
|
|
2021-05-26 15:22:44 +00:00
|
|
|
#[derive(Props, PartialEq)]
|
|
|
|
struct ChildProps {
|
|
|
|
id: Uuid,
|
|
|
|
}
|
|
|
|
|
2021-06-26 01:15:33 +00:00
|
|
|
static Child: FC<ChildProps> = |cx| {
|
|
|
|
let (todo, set_todo) = use_read_write(cx, &TODOS.select(&cx.id));
|
2021-05-26 15:22:44 +00:00
|
|
|
|
2021-06-26 01:15:33 +00:00
|
|
|
rsx! { in cx,
|
2021-05-31 22:55:56 +00:00
|
|
|
li {
|
2021-05-26 15:22:44 +00:00
|
|
|
h1 {"{todo.title}"}
|
|
|
|
input { type: "checkbox", name: "scales", checked: "{todo.checked}" }
|
2021-05-31 22:55:56 +00:00
|
|
|
label { "{todo.content}", for: "scales" }
|
|
|
|
p {"{todo.content}"}
|
2021-05-26 05:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
wasm_bindgen_futures::spawn_local(dioxus_web::WebsysRenderer::start(App))
|
|
|
|
}
|