diff --git a/src/components/Tasks/Sidebar.tsx b/src/components/Tasks/Sidebar.tsx index 89a705a..5af5f2b 100644 --- a/src/components/Tasks/Sidebar.tsx +++ b/src/components/Tasks/Sidebar.tsx @@ -10,6 +10,9 @@ import { setSettings } from '../../store/actions'; import { StoreState } from '../../store'; import { List, ListItem, ListSubheader } from '../../widgets/List'; +import { TaskType } from '../../pim-types'; + +import moment from 'moment'; interface ListItemPropsType { name: string | null; @@ -39,8 +42,17 @@ function SidebarListItem(props: ListItemPropsType) { ); } -export default function Sidebar(props: { tags: Map, totalTasks: number }) { - const { tags, totalTasks } = props; +export default function Sidebar(props: { tasks: TaskType[] }) { + const { tasks } = props; + + // TODO: memoize + const amountDueToday = tasks.filter((x) => x.dueDate && moment(x.dueDate.toJSDate()).isSame(moment(), 'day')).length; + + // TODO: memoize + const tags = new Map(); + tasks.forEach((task) => task.tags.forEach((tag) => { + tags.set(tag, (tags.get(tag) ?? 0) + 1); + })); const tagsList = [...tags].sort(([a], [b]) => a.localeCompare(b)).map(([tag, amount]) => ( , totalTasks: return ( - } amount={totalTasks} /> - } /> + } amount={tasks.length} /> + } amount={amountDueToday} /> Tags {tagsList} diff --git a/src/components/Tasks/TaskList.tsx b/src/components/Tasks/TaskList.tsx index ac9f16e..9269f61 100644 --- a/src/components/Tasks/TaskList.tsx +++ b/src/components/Tasks/TaskList.tsx @@ -58,12 +58,6 @@ export default React.memo(function TaskList(props: PropsType) { entries = potentialEntries; } - // TODO: memoize - const tags = new Map(); - potentialEntries.forEach((entry) => entry.tags.forEach((tag) => { - tags.set(tag, (tags.get(tag) ?? 0) + 1); - })); - // sort const sortedEntries = sortSelector(entries); @@ -84,7 +78,7 @@ export default React.memo(function TaskList(props: PropsType) { - +