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
|
|
|
}
|
|
|
|
|
|
|
|
static App: FC<()> = |ctx, _| {
|
2021-05-31 22:55:56 +00:00
|
|
|
use_init_recoil_root(ctx, move |cfg| {});
|
|
|
|
|
2021-05-27 21:57:59 +00:00
|
|
|
let todos = use_read_family(ctx, &TODOS);
|
2021-05-26 15:22:44 +00:00
|
|
|
|
2021-05-31 22:55:56 +00:00
|
|
|
// rsx! { in ctx,
|
|
|
|
// div {
|
|
|
|
// h1 {"Basic Todolist with AtomFamilies in Recoil.rs"}
|
|
|
|
// ul { { todos.keys().map(|id| rsx! { Child { id: *id } }) } }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
ctx.render(html! {
|
|
|
|
<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,
|
|
|
|
}
|
|
|
|
|
|
|
|
static Child: FC<ChildProps> = |ctx, props| {
|
2021-05-27 21:57:59 +00:00
|
|
|
let (todo, set_todo) = use_read_write(ctx, &TODOS.select(&props.id));
|
2021-05-26 15:22:44 +00:00
|
|
|
|
2021-05-26 05:40:30 +00:00
|
|
|
rsx! { in ctx,
|
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))
|
|
|
|
}
|