From 65a3991d9422470e1b4af31074cddb5cd1ed8382 Mon Sep 17 00:00:00 2001 From: Nathan Arthur Date: Tue, 8 Nov 2022 16:41:14 -0500 Subject: [PATCH] move sorting into createListItems --- src/App.tsx | 1 - src/components/organisms/TaskList.tsx | 7 ++++--- src/components/pages/Tasks.spec.tsx | 1 - src/lib/createListItems.tsx | 6 ++++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index ae85b870..e2dc9ef8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -14,7 +14,6 @@ import 'react-toastify/dist/ReactToastify.css'; import { IS_PRODUCTION } from './tr_constants'; import { QueryClientProvider } from 'react-query'; import NavBar from './components/organisms/NavBar'; -import browser from './lib/Browser'; import { Box, Container, CssBaseline, Stack, Alert } from '@mui/material'; import { H } from 'highlight.run'; import getQueryClient from './lib/getQueryClient'; diff --git a/src/components/organisms/TaskList.tsx b/src/components/organisms/TaskList.tsx index a40f674d..d66fa6b4 100644 --- a/src/components/organisms/TaskList.tsx +++ b/src/components/organisms/TaskList.tsx @@ -25,12 +25,13 @@ const TaskList = ({ newTask }: TaskListProps): JSX.Element => { const [shouldScroll, setShouldScroll] = useState(false); useEffect(() => { - const sorted = sortTasks(tasks || []); - const filtered = filters ? sorted.filter((t) => filters[t.status]) : sorted; + const filtered = filters + ? (tasks ?? []).filter((t) => filters[t.status]) + : tasks ?? []; const { entries: newEntries, newTaskIndex: taskIndexUpdate } = createListItems({ - sortedTasks: filtered, + tasks: filtered, newTask, }); diff --git a/src/components/pages/Tasks.spec.tsx b/src/components/pages/Tasks.spec.tsx index 51d2184e..be898d87 100644 --- a/src/components/pages/Tasks.spec.tsx +++ b/src/components/pages/Tasks.spec.tsx @@ -12,7 +12,6 @@ import { makeTask } from '../../lib/test/makeTask'; import { withMutedReactQueryLogger } from '../../lib/test/withMutedReactQueryLogger'; import { getUnloadMessage } from '../../lib/getUnloadMessage'; import browser from '../../lib/Browser'; -import { __listRef } from '../../../__mocks__/react-list'; import { editTask } from '../../lib/api/editTask'; import { vi, Mock, describe, it, expect, beforeEach } from 'vitest'; import loadControlledPromise from '../../lib/test/loadControlledPromise'; diff --git a/src/lib/createListItems.tsx b/src/lib/createListItems.tsx index fab08947..dc033886 100644 --- a/src/lib/createListItems.tsx +++ b/src/lib/createListItems.tsx @@ -1,4 +1,5 @@ import browser from './Browser'; +import { sortTasks } from './sortTasks'; function makeTitle(task: TaskType) { return browser.getString(new Date(task.due)); @@ -13,16 +14,17 @@ const isNewTask = (t: TaskType, n: TaskType | undefined): boolean => { type Entries = (TaskType | string)[]; type Options = { - sortedTasks: TaskType[]; + tasks: TaskType[]; newTask: TaskType | undefined; }; -export default function createListItems({ sortedTasks, newTask }: Options): { +export default function createListItems({ tasks, newTask }: 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;