wip: refactor a bit

This commit is contained in:
Jonathan Kelley committed 2021-04-04 21:47:53 -04:00
1 parent 8c541f66d5
commit 2eeb8f2386
9 files changed
+553 -297

No files matched your search

+21 -19
View File
@@ -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(||