diff --git a/src/components/organisms/TaskList.tsx b/src/components/organisms/TaskList.tsx index 69047e6f..d68b5931 100644 --- a/src/components/organisms/TaskList.tsx +++ b/src/components/organisms/TaskList.tsx @@ -5,6 +5,7 @@ import ReactList from 'react-list'; import { Alert, AlertTitle, ListSubheader } from '@mui/material'; import Task from '../molecules/Task'; import useFilters from '../../lib/useFilters'; +import browser from '../../lib/Browser'; interface TaskListProps { newTask?: TaskType; @@ -32,6 +33,7 @@ const TaskList = ({ newTask }: TaskListProps): JSX.Element => { createListItems({ tasks: filtered, newTask, + minDue: browser.getLastMidnight(), }); setEntries(newEntries); diff --git a/src/lib/Browser.tsx b/src/lib/Browser.tsx index ec22c4c6..8f93529c 100644 --- a/src/lib/Browser.tsx +++ b/src/lib/Browser.tsx @@ -90,7 +90,7 @@ export class Browser { return el.scrollTop / (el.scrollHeight - el.clientHeight); } - getLastMidnight(date: Date): Date { + getLastMidnight(date: Date = browser.getNowDate()): Date { const d = new Date(date); d.setHours(0, 0, 0, 0); return d; diff --git a/src/lib/createListItems.tsx b/src/lib/createListItems.tsx index dc033886..2e8cd166 100644 --- a/src/lib/createListItems.tsx +++ b/src/lib/createListItems.tsx @@ -16,21 +16,20 @@ type Entries = (TaskType | string)[]; type Options = { tasks: TaskType[]; newTask: TaskType | undefined; + minDue: Date; }; -export default function createListItems({ tasks, newTask }: Options): { +export default function createListItems({ tasks, newTask, minDue }: Options): { entries: Entries; newTaskIndex: number | undefined; } { - const now = browser.getNowDate(); - const lastMidnight = browser.getLastMidnight(now); const sortedTasks = sortTasks(tasks); let lastTitle: string; let newTaskIndex: number | undefined = undefined; const entries = sortedTasks.reduce((acc: Entries, t: TaskType): Entries => { - if (new Date(t.due) < lastMidnight) return acc; + if (new Date(t.due) < minDue) return acc; const title = makeTitle(t); const shouldAddHeading = title !== lastTitle || !acc.length;