From 6ea7bd79cfe150290b7d5ec4d666b2744fc35c1a Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 16 Jul 2020 13:07:25 +0300 Subject: [PATCH] Task list: implement 1-level task hierarchy. This is the first step towards fixing #124 --- src/components/Tasks/TaskList.tsx | 16 +++++++++++++++- src/components/Tasks/TaskListItem.tsx | 9 +++++++-- src/pim-types.ts | 12 ++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/components/Tasks/TaskList.tsx b/src/components/Tasks/TaskList.tsx index feb742d..11ac050 100644 --- a/src/components/Tasks/TaskList.tsx +++ b/src/components/Tasks/TaskList.tsx @@ -208,6 +208,19 @@ export default function TaskList(props: PropsType) { entries = potentialEntries; } + const subEntriesMap = new Map(); + + entries = entries.filter((x) => { + const relatedTo = x.relatedTo; + if (relatedTo) { + const cur = subEntriesMap.get(relatedTo) ?? []; + cur.push(x); + subEntriesMap.set(relatedTo, cur); + return false; + } + return true; + }); + const sortedEntries = entries.sort(getSortFunction(sortBy)); const itemList = sortedEntries.map((entry) => { @@ -217,8 +230,9 @@ export default function TaskList(props: PropsType) { handleToggleComplete(entry, completed)} + onToggleComplete={(entry: TaskType, completed: boolean) => handleToggleComplete(entry, completed)} /> ); }); diff --git a/src/components/Tasks/TaskListItem.tsx b/src/components/Tasks/TaskListItem.tsx index 50178e3..084add8 100644 --- a/src/components/Tasks/TaskListItem.tsx +++ b/src/components/Tasks/TaskListItem.tsx @@ -34,13 +34,15 @@ const TagsList = React.memo((props: { tags: string[] }) => ( interface PropsType { entry: TaskType; + subEntries?: TaskType[]; onClick: (task: TaskType) => void; - onToggleComplete: (completed: boolean) => void; + onToggleComplete: (task: TaskType, completed: boolean) => void; } export default React.memo(function TaskListItem(props: PropsType) { const { entry: task, + subEntries, onClick, onToggleComplete, } = props; @@ -55,11 +57,14 @@ export default React.memo(function TaskListItem(props: PropsType) { primaryText={title} secondaryText={secondaryText} secondaryTextColor={task.overdue ? 'error' : 'textSecondary'} + nestedItems={subEntries?.map((x) => ( + + ))} onClick={() => onClick(task)} leftIcon={ e.stopPropagation()} - onChange={(_e, checked) => onToggleComplete(checked)} + onChange={(_e, checked) => onToggleComplete(task, checked)} checked={task.finished} icon={} /> diff --git a/src/pim-types.ts b/src/pim-types.ts index 2f5ee69..588fc61 100644 --- a/src/pim-types.ts +++ b/src/pim-types.ts @@ -226,6 +226,18 @@ export class TaskType extends EventType { return this.component.getFirstPropertyValue('completed'); } + set relatedTo(parentUid: string | undefined) { + if (parentUid !== undefined) { + this.component.updatePropertyWithValue('related-to', parentUid); + } else { + this.component.removeAllProperties('related-to'); + } + } + + get relatedTo(): string | undefined { + return this.component.getFirstPropertyValue('related-to'); + } + get endDate() { // XXX: A hack to override this as it shouldn't be used return undefined as any;