Skip to content

Commit

Permalink
move sorting into createListItems
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Nov 8, 2022
1 parent 3ba0102 commit 65a3991
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 4 additions & 3 deletions src/components/organisms/TaskList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ const TaskList = ({ newTask }: TaskListProps): JSX.Element => {
const [shouldScroll, setShouldScroll] = useState<boolean>(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,
});

Expand Down
1 change: 0 additions & 1 deletion src/components/pages/Tasks.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 4 additions & 2 deletions src/lib/createListItems.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import browser from './Browser';
import { sortTasks } from './sortTasks';

function makeTitle(task: TaskType) {
return browser.getString(new Date(task.due));
Expand All @@ -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;
Expand Down

1 comment on commit 65a3991

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.