Tasks: adds dueToday getter to TaskType

cleans up some code around filtering by due today
master
Andrew P Maney 5 years ago committed by Tom Hacohen
parent 9a7960556b
commit 716240e266

@ -12,8 +12,6 @@ import { StoreState } from '../../store';
import { List, ListItem, ListSubheader } from '../../widgets/List'; import { List, ListItem, ListSubheader } from '../../widgets/List';
import { TaskType } from '../../pim-types'; import { TaskType } from '../../pim-types';
import moment from 'moment';
interface ListItemPropsType { interface ListItemPropsType {
name: string | null; name: string | null;
icon?: React.ReactElement; icon?: React.ReactElement;
@ -45,7 +43,7 @@ function SidebarListItem(props: ListItemPropsType) {
export default React.memo(function Sidebar(props: { tasks: TaskType[] }) { export default React.memo(function Sidebar(props: { tasks: TaskType[] }) {
const { tasks } = props; const { tasks } = props;
const amountDueToday = tasks.filter((x) => x.dueDate && moment(x.dueDate.toJSDate()).isSame(moment(), 'day')).length; const amountDueToday = tasks.filter((x) => x.dueToday).length;
const tags = new Map<string, number>(); const tags = new Map<string, number>();
tasks.forEach((task) => task.tags.forEach((tag) => { tasks.forEach((task) => task.tags.forEach((tag) => {

@ -24,8 +24,6 @@ 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))
@ -56,7 +54,7 @@ export default function TaskList(props: PropsType) {
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') { } else if (filterBy === 'today') {
entries = potentialEntries.filter((x) => x.dueDate && moment(x.dueDate.toJSDate()).isSame(moment(), 'day')); entries = potentialEntries.filter((x) => x.dueToday);
} else { } else {
entries = potentialEntries; entries = potentialEntries;
} }

@ -3,6 +3,7 @@
import * as ICAL from 'ical.js'; import * as ICAL from 'ical.js';
import * as zones from './data/zones.json'; import * as zones from './data/zones.json';
import moment from 'moment';
export const PRODID = '-//iCal.js EteSync iOS'; export const PRODID = '-//iCal.js EteSync iOS';
@ -225,6 +226,10 @@ export class TaskType extends EventType {
return !!((this.startDate?.isDate) || (this.dueDate?.isDate)); return !!((this.startDate?.isDate) || (this.dueDate?.isDate));
} }
get dueToday() {
return this.dueDate && moment(this.dueDate.toJSDate()).isSame(moment(), 'day');
}
public clone() { public clone() {
const ret = new TaskType(new ICAL.Component(this.component.toJSON())); const ret = new TaskType(new ICAL.Component(this.component.toJSON()));
ret.color = this.color; ret.color = this.color;

Loading…
Cancel
Save