Skip to content

Commit

Permalink
Task list: support infinitely deep task hierarchies.
Browse files Browse the repository at this point in the history
Another step towards fixing #124.
  • Loading branch information
tasn committed Jul 16, 2020
1 parent 484825b commit ad6ac59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 11 additions & 7 deletions src/components/Tasks/TaskList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export default function TaskList(props: PropsType) {
const classes = useStyles();
const dispatch = useDispatch();

const { onItemClick } = props;

const handleToggleComplete = (task: TaskType, completed: boolean) => {
const clonedTask = task.clone();
clonedTask.status = completed ? TaskStatusType.Completed : TaskStatusType.NeedsAction;
Expand Down Expand Up @@ -222,21 +224,23 @@ export default function TaskList(props: PropsType) {
return true;
});

const sortedEntries = entries.sort(getSortFunction(sortBy));

const itemList = sortedEntries.map((entry) => {
function taskListItemFromTask(entry: TaskType) {
const uid = entry.uid;

return (
<TaskListItem
key={uid}
entry={entry}
subEntries={subEntriesMap.get(uid)}
onClick={props.onItemClick}
onToggleComplete={(entry: TaskType, completed: boolean) => handleToggleComplete(entry, completed)}
nestedItems={subEntriesMap.get(uid)?.map(taskListItemFromTask)}
onClick={onItemClick}
onToggleComplete={handleToggleComplete}
/>
);
});
}

const sortedEntries = entries.sort(getSortFunction(sortBy));

const itemList = sortedEntries.map(taskListItemFromTask);

return (
<Grid container spacing={4}>
Expand Down
8 changes: 3 additions & 5 deletions src/components/Tasks/TaskListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ const TagsList = React.memo((props: { tags: string[] }) => (

interface PropsType {
entry: TaskType;
subEntries?: TaskType[];
nestedItems?: React.ReactNode[];
onClick: (task: TaskType) => void;
onToggleComplete: (task: TaskType, completed: boolean) => void;
}

export default React.memo(function TaskListItem(props: PropsType) {
const {
entry: task,
subEntries,
nestedItems,
onClick,
onToggleComplete,
} = props;
Expand All @@ -57,9 +57,7 @@ export default React.memo(function TaskListItem(props: PropsType) {
primaryText={title}
secondaryText={secondaryText}
secondaryTextColor={task.overdue ? 'error' : 'textSecondary'}
nestedItems={subEntries?.map((x) => (
<TaskListItem key={x.uid} entry={x} onClick={onClick} onToggleComplete={onToggleComplete} />
))}
nestedItems={nestedItems}
onClick={() => onClick(task)}
leftIcon={
<Checkbox
Expand Down

0 comments on commit ad6ac59

Please sign in to comment.