1
0

state.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. use crate::recoil::*;
  2. use dioxus_core::prelude::Context;
  3. pub static TODOS: AtomFamily<uuid::Uuid, TodoItem> = atom_family(|_| {});
  4. pub static FILTER: Atom<FilterState> = atom(|_| FilterState::All);
  5. pub static SHOW_ALL_TODOS: selector<bool> = selector(|g| g.getter(|f| false));
  6. // an atomfamily is just a HashMap<K, Pin<Rc<V>>> that pins the Rc and exposes the values by reference
  7. // we could do a more advanced management, but this is fine too
  8. #[derive(PartialEq)]
  9. pub enum FilterState {
  10. All,
  11. Active,
  12. Completed,
  13. }
  14. #[derive(Debug, PartialEq, Clone)]
  15. pub struct TodoItem {
  16. pub id: uuid::Uuid,
  17. pub checked: bool,
  18. pub contents: String,
  19. }
  20. pub fn add_todo(ctx: &Context, contents: String) {}
  21. pub fn remove_todo(ctx: &Context, id: &uuid::Uuid) {
  22. TODOS.with(&ctx).remove(id)
  23. }
  24. pub fn select_all_todos(ctx: &Context) {}
  25. pub fn toggle_todo(ctx: &Context, id: &uuid::Uuid) {}
  26. pub fn clear_completed(ctx: &Context) {
  27. let (set, get) = (self.set, self.get);
  28. TOODS
  29. .get(&ctx)
  30. .iter()
  31. .filter(|(k, v)| v.checked)
  32. .map(|(k, v)| TODOS.remove(&ctx, k));
  33. }
  34. pub fn set_filter(ctx: &Context, filter: &FilterState) {}
  35. struct TodoManager<'a> {}
  36. fn use_todos(ctx: &Context) {}
  37. #[test]
  38. fn test() {}