wip: refactor a bit
This commit is contained in:
1 parent
8c541f66d5
commit
2eeb8f2386
9 files changed
+553
-297
No files matched your search
@@ -93,8 +93,9 @@ mod selectors {
|
||||
}
|
||||
impl<O> SelectorBuilder<O, false> {
|
||||
pub fn getter(self, f: impl Fn(()) -> O) -> SelectorBuilder<O, true> {
|
||||
std::rc::Rc::pin(value)
|
||||
todo!()
|
||||
// std::rc::Rc::pin(value)
|
||||
// todo!()
|
||||
}
|
||||
}
|
||||
pub struct selector<O>(pub fn(SelectorBuilder<O, false>) -> SelectorBuilder<O, true>);
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
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 {
|
||||
All,
|
||||
@@ -22,30 +18,26 @@ pub struct TodoItem {
|
||||
pub contents: String,
|
||||
}
|
||||
|
||||
pub fn add_todo(ctx: &Context, contents: String) {}
|
||||
impl RecoilContext<()> {
|
||||
pub fn add_todo(&self, contents: String) {}
|
||||
|
||||
pub fn remove_todo(ctx: &Context, id: &uuid::Uuid) {
|
||||
TODOS.with(&ctx).remove(id)
|
||||
pub fn remove_todo(&self, id: &uuid::Uuid) {
|
||||
// TODOS.with().remove(id)
|
||||
}
|
||||
|
||||
pub fn select_all_todos(&self) {}
|
||||
|
||||
pub fn toggle_todo(&self, id: &uuid::Uuid) {}
|
||||
|
||||
pub fn clear_completed(&self) {
|
||||
// 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(&self, filter: &FilterState) {}
|
||||
}
|
||||
|
||||
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() {}
|
||||
@@ -1,7 +1,9 @@
|
||||
use super::state::{FilterState, TodoItem, FILTER, TODOS};
|
||||
use crate::filtertoggles;
|
||||
use crate::recoil::use_atom;
|
||||
use crate::todoitem::TodoEntry;
|
||||
use crate::{
|
||||
filtertoggles,
|
||||
recoil::use_atom,
|
||||
state::{FilterState, TodoItem, FILTER, TODOS},
|
||||
todoitem::TodoEntry,
|
||||
};
|
||||
use dioxus_core::prelude::*;
|
||||
|
||||
pub fn TodoList(ctx: Context, props: &()) -> DomTree {
|
||||
@@ -9,20 +11,6 @@ pub fn TodoList(ctx: Context, props: &()) -> DomTree {
|
||||
let (todos, _) = use_state(&ctx, || Vec::<TodoItem>::new());
|
||||
let filter = use_atom(&ctx, &FILTER);
|
||||
|
||||
let list = todos
|
||||
.iter()
|
||||
.filter(|item| match filter {
|
||||
FilterState::All => true,
|
||||
FilterState::Active => !item.checked,
|
||||
FilterState::Completed => item.checked,
|
||||
})
|
||||
.map(|item| {
|
||||
rsx!(TodoEntry {
|
||||
key: "{order}",
|
||||
id: item.id,
|
||||
})
|
||||
});
|
||||
|
||||
ctx.render(rsx! {
|
||||
div {
|
||||
header {
|
||||
@@ -36,7 +24,21 @@ pub fn TodoList(ctx: Context, props: &()) -> DomTree {
|
||||
}
|
||||
}
|
||||
|
||||
{list}
|
||||
{ // list
|
||||
todos
|
||||
.iter()
|
||||
.filter(|item| match filter {
|
||||
FilterState::All => true,
|
||||
FilterState::Active => !item.checked,
|
||||
FilterState::Completed => item.checked,
|
||||
})
|
||||
.map(|item| {
|
||||
rsx!(TodoEntry {
|
||||
key: "{order}",
|
||||
id: item.id,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// filter toggle (show only if the list isn't empty)
|
||||
{(!todos.is_empty()).then(||
|
||||
|
||||
Reference in new issue
Block a user