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

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

Loading…
Cancel
Save