diff --git a/src/components/Tasks/Sidebar.tsx b/src/components/Tasks/Sidebar.tsx index 3c47821..e9b9bab 100644 --- a/src/components/Tasks/Sidebar.tsx +++ b/src/components/Tasks/Sidebar.tsx @@ -12,8 +12,6 @@ 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; icon?: React.ReactElement; @@ -45,7 +43,7 @@ function SidebarListItem(props: ListItemPropsType) { export default React.memo(function Sidebar(props: { tasks: TaskType[] }) { const { tasks } = props; - const amountDueToday = tasks.filter((x) => x.dueDate && moment(x.dueDate.toJSDate()).isSame(moment(), 'day')).length; + const amountDueToday = tasks.filter((x) => x.dueToday).length; const tags = new Map(); tasks.forEach((task) => task.tags.forEach((tag) => { diff --git a/src/components/Tasks/TaskList.tsx b/src/components/Tasks/TaskList.tsx index 4fd5bfb..9174f01 100644 --- a/src/components/Tasks/TaskList.tsx +++ b/src/components/Tasks/TaskList.tsx @@ -24,8 +24,6 @@ import Sidebar from './Sidebar'; import { StoreState } from '../../store'; -import moment from 'moment'; - const sortSelector = createSelector( (entries: TaskType[]) => entries, (entries) => entries.sort((a, b) => a.title.localeCompare(b.title)) @@ -56,7 +54,7 @@ export default function TaskList(props: PropsType) { const tag = filterBy.slice(tagPrefix.length); entries = potentialEntries.filter((x) => x.tags.includes(tag)); } else if (filterBy === 'today') { - entries = potentialEntries.filter((x) => x.dueDate && moment(x.dueDate.toJSDate()).isSame(moment(), 'day')); + entries = potentialEntries.filter((x) => x.dueToday); } else { entries = potentialEntries; } diff --git a/src/pim-types.ts b/src/pim-types.ts index e0516dd..ec74082 100644 --- a/src/pim-types.ts +++ b/src/pim-types.ts @@ -3,6 +3,7 @@ import * as ICAL from 'ical.js'; import * as zones from './data/zones.json'; +import moment from 'moment'; export const PRODID = '-//iCal.js EteSync iOS'; @@ -225,6 +226,10 @@ export class TaskType extends EventType { return !!((this.startDate?.isDate) || (this.dueDate?.isDate)); } + get dueToday() { + return this.dueDate && moment(this.dueDate.toJSDate()).isSame(moment(), 'day'); + } + public clone() { const ret = new TaskType(new ICAL.Component(this.component.toJSON())); ret.color = this.color;