wip: todos

This commit is contained in:
Jonathan Kelley committed 2021-04-01 21:44:18 -04:00
1 parent cfa0927cdd
commit 8c541f66d5
14 files changed
+257 -109

No files matched your search

+31 -7
View File
@@ -1,7 +1,12 @@
use crate::recoil::*;
use dioxus_core::prelude::Context;
pub static TODOS: AtomFamily<uuid::Uuid, TodoItem> = atom_family(|_| {});
pub static FILTER: Atom<FilterState> = atom(|_| FilterState::All);
pub static SHOW_ALL_TODOS: selector<bool> = selector(|g| g.getter(|f| false));
// an atomfamily is just a HashMap<K, Pin<Rc<V>>> that pins the Rc and exposes the values by reference
// we could do a more advanced management, but this is fine too
#[derive(PartialEq)]
pub enum FilterState {
@@ -17,11 +22,30 @@ pub struct TodoItem {
pub contents: String,
}
impl crate::recoil::RecoilContext<()> {
pub fn add_todo(&self, contents: String) {}
pub fn remove_todo(&self) {}
pub fn select_all_todos(&self) {}
pub fn toggle_todo(&self, id: uuid::Uuid) {}
pub fn clear_completed(&self) {}
pub fn set_filter(&self, filter: &FilterState) {}
pub fn add_todo(ctx: &Context, contents: String) {}
pub fn remove_todo(ctx: &Context, id: &uuid::Uuid) {
TODOS.with(&ctx).remove(id)
}
pub fn select_all_todos(ctx: &Context) {}
pub fn toggle_todo(ctx: &Context, id: &uuid::Uuid) {}
pub fn clear_completed(ctx: &Context) {
let (set, get) = (self.set, self.get);
TOODS
.get(&ctx)
.iter()
.filter(|(k, v)| v.checked)
.map(|(k, v)| TODOS.remove(&ctx, k));
}
pub fn set_filter(ctx: &Context, filter: &FilterState) {}
struct TodoManager<'a> {}
fn use_todos(ctx: &Context) {}
#[test]
fn test() {}