From ed4ed868808395eaf5c71568598cc4d02e53f9e1 Mon Sep 17 00:00:00 2001 From: Andrew P Maney Date: Mon, 30 Mar 2020 07:01:38 -0700 Subject: [PATCH] Tasks: add show/hide hidden feature --- src/components/Tasks/TaskList.tsx | 7 +++++-- src/components/Tasks/Toolbar.tsx | 11 ++++++++++- src/pim-types.ts | 10 ++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/components/Tasks/TaskList.tsx b/src/components/Tasks/TaskList.tsx index 0cc9ae7..73e3876 100644 --- a/src/components/Tasks/TaskList.tsx +++ b/src/components/Tasks/TaskList.tsx @@ -105,6 +105,7 @@ interface PropsType { export default function TaskList(props: PropsType) { const [showCompleted, setShowCompleted] = React.useState(false); + const [showHidden, setShowHidden] = React.useState(false); const [searchTerm, setSearchTerm] = React.useState(''); const settings = useSelector((state: StoreState) => state.settings.taskSettings); const { filterBy, sortBy } = settings; @@ -126,10 +127,10 @@ export default function TaskList(props: PropsType) { }).search(searchTerm); return result.map((x) => x.item); } else { - return props.entries.filter((x) => showCompleted || !x.finished); + return props.entries.filter((x) => (showCompleted || !x.finished) && (showHidden || !x.hidden)); } }, - [showCompleted, props.entries, searchTerm] + [showCompleted, props.entries, searchTerm, showHidden] ); let entries; @@ -173,6 +174,8 @@ export default function TaskList(props: PropsType) { setShowCompleted={setShowCompleted} searchTerm={searchTerm} setSearchTerm={setSearchTerm} + showHidden={showHidden} + setShowHidden={setShowHidden} /> diff --git a/src/components/Tasks/Toolbar.tsx b/src/components/Tasks/Toolbar.tsx index 40ca60b..59a1a42 100644 --- a/src/components/Tasks/Toolbar.tsx +++ b/src/components/Tasks/Toolbar.tsx @@ -47,13 +47,15 @@ interface PropsType { defaultCollection: EteSync.CollectionInfo; onItemSave: (item: PimType, journalUid: string, originalItem?: PimType) => Promise; showCompleted: boolean; + showHidden: boolean; setShowCompleted: (completed: boolean) => void; + setShowHidden: (hidden: boolean) => void; searchTerm: string; setSearchTerm: (term: string) => void; } export default function Toolbar(props: PropsType) { - const { showCompleted, setShowCompleted, searchTerm, setSearchTerm } = props; + const { showCompleted, setShowCompleted, searchTerm, setSearchTerm, showHidden, setShowHidden } = props; const [showSearchField, setShowSearchField] = React.useState(false); const [sortAnchorEl, setSortAnchorEl] = React.useState(null); @@ -164,6 +166,13 @@ export default function Toolbar(props: PropsType) { control={ setShowCompleted(checked)} />} /> + + setShowHidden(checked)} />} + /> + diff --git a/src/pim-types.ts b/src/pim-types.ts index 939f8ac..e2a4e19 100644 --- a/src/pim-types.ts +++ b/src/pim-types.ts @@ -240,6 +240,16 @@ export class TaskType extends EventType { return (this.dueDate.isDate) ? dueDate.isBefore(now, 'day') : dueDate.isBefore(now); } + get hidden() { + if (!this.startDate) { + return false; + } + + const startDate = moment(this.startDate.toJSDate()); + const now = moment(); + return startDate.isAfter(now); + } + public clone() { const ret = new TaskType(new ICAL.Component(this.component.toJSON())); ret.color = this.color;