Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
feat(commands): #13 sort by due date by default
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #13
  • Loading branch information
moranje committed Feb 16, 2020
1 parent 962b556 commit 32044b0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/lib/commands/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import {
zhTW,
} from 'date-fns/locale';
import parseISO from 'date-fns/parseISO';
import sort from 'fast-sort';
import { TodoistTask } from 'todoist-rest-api';

import { getApi, requestError } from '../todoist';
import { createCall } from '@/lib/cli-args';
import {
listLabels,
Expand All @@ -36,6 +36,8 @@ import { parser } from '@/lib/todoist/parser';
import { Item, List, workflowList } from '@/lib/workflow';
import readTasksView from '@/lib/workflow/views/read-tasks';

import { getApi, requestError } from '../todoist';

const LOCALES = {
da,
de,
Expand Down Expand Up @@ -263,7 +265,9 @@ export async function read(query: string): Promise<void> {
sectionId: parsed.section?.id,
});
const list = await mapTasks(
filteredTasks.slice(0, settingsStore().get('max_items'))
sort(filteredTasks)
.asc(task => task?.due?.datetime ?? task?.due?.date)
.slice(0, settingsStore().get('max_items'))
);
list.push(listRefreshItem('task'));

Expand Down
4 changes: 2 additions & 2 deletions src/tests/read-remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ describe('integration: Read()', () => {
await command({ name: 'read', args: '' });

expect(stdoutSpy.mock.calls[0][0]).toContainAllAlfredItemsWith('title', [
'COMPLETE: Project review',
'COMPLETE: Sign up for dance class',
'COMPLETE: Get milk',
'COMPLETE: Plan a thing',
'COMPLETE: Buy the thing',
'COMPLETE: Sign up for dance class',
'COMPLETE: Project review',
'REFRESH CACHE',
]);
});
Expand Down
4 changes: 2 additions & 2 deletions src/tests/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ describe('integration: Read()', () => {
await command({ name: 'read', args: '' });

expect(stdoutSpy.mock.calls[0][0]).toContainAllAlfredItemsWith('title', [
'COMPLETE: Project review (local)',
'COMPLETE: Sign up for dance class (local)',
'COMPLETE: Get milk (local)',
'COMPLETE: Plan a thing (local)',
'COMPLETE: Buy the thing (local)',
'COMPLETE: Sign up for dance class (local)',
'COMPLETE: Project review (local)',
'REFRESH CACHE',
]);
});
Expand Down

0 comments on commit 32044b0

Please sign in to comment.