Tasks: adds filter by Due Today

master
Andrew P Maney 5 years ago committed by Tom Hacohen
parent 02ac73eb25
commit 2980305beb

@ -4,6 +4,7 @@ import { useSelector, useDispatch } from 'react-redux';
import InboxIcon from '@material-ui/icons/Inbox'; import InboxIcon from '@material-ui/icons/Inbox';
import LabelIcon from '@material-ui/icons/LabelOutlined'; import LabelIcon from '@material-ui/icons/LabelOutlined';
import TodayIcon from '@material-ui/icons/Today';
import { setSettings } from '../../store/actions'; import { setSettings } from '../../store/actions';
import { StoreState } from '../../store'; import { StoreState } from '../../store';
@ -54,6 +55,7 @@ export default function Sidebar(props: { tags: Map<string, number>, totalTasks:
return ( return (
<List dense> <List dense>
<SidebarListItem name={null} primaryText="All" icon={<InboxIcon />} amount={totalTasks} /> <SidebarListItem name={null} primaryText="All" icon={<InboxIcon />} amount={totalTasks} />
<SidebarListItem name="today" primaryText="Due today" icon={<TodayIcon />} />
<ListSubheader>Tags</ListSubheader> <ListSubheader>Tags</ListSubheader>
{tagsList} {tagsList}

@ -24,6 +24,8 @@ import Sidebar from './Sidebar';
import { StoreState } from '../../store'; import { StoreState } from '../../store';
import moment from 'moment';
const sortSelector = createSelector( const sortSelector = createSelector(
(entries: TaskType[]) => entries, (entries: TaskType[]) => entries,
(entries) => entries.sort((a, b) => a.title.localeCompare(b.title)) (entries) => entries.sort((a, b) => a.title.localeCompare(b.title))
@ -44,10 +46,14 @@ export default React.memo(function TaskList(props: PropsType) {
const potentialEntries = props.entries.filter((x) => showCompleted || !x.finished); const potentialEntries = props.entries.filter((x) => showCompleted || !x.finished);
let entries; let entries;
// filter
const tagPrefix = 'tag:'; const tagPrefix = 'tag:';
if (filterBy?.startsWith(tagPrefix)) { if (filterBy?.startsWith(tagPrefix)) {
const tag = filterBy.slice(tagPrefix.length); const tag = filterBy.slice(tagPrefix.length);
entries = potentialEntries.filter((x) => x.tags.includes(tag)); 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'));
} else { } else {
entries = potentialEntries; entries = potentialEntries;
} }
@ -58,6 +64,7 @@ export default React.memo(function TaskList(props: PropsType) {
tags.set(tag, (tags.get(tag) ?? 0) + 1); tags.set(tag, (tags.get(tag) ?? 0) + 1);
})); }));
// sort
const sortedEntries = sortSelector(entries); const sortedEntries = sortSelector(entries);
const itemList = sortedEntries.map((entry) => { const itemList = sortedEntries.map((entry) => {

Loading…
Cancel
Save